Kohei Yamamoto
/
F303k8-toy-c-test
for20210702
Diff: main.cpp
- Revision:
- 0:4bb9fdb82508
- Child:
- 1:fb2003e84b92
diff -r 000000000000 -r 4bb9fdb82508 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jul 01 12:15:17 2021 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" +Serial xbee(D1,D0);//TX,RXの順。要確認。 +PwmOut servo1(D11); +PwmOut servo2(D12); +DigitalOut led(LED3);//何かに使いたいね +int value; + +float calc(float x){ + return (1.45+(2.4-0.5)/180*x)/1000; +} +float nowarg = -1; +float cnowarg = -1; + +int main() +{ + led = 1; + wait(0.25); + led = 0; + wait(0.25); + led = 1; + wait(0.25); + led = 0; + wait(0.25); + printf("\nToy-C example\n"); + while(1) { + //Xbeeの受信 + if (xbee.readable()){ + value = xbee.getc(); + if (value==1){//1を受信した時 + nowarg = 90; + cnowarg = calc(nowarg); + servo1.pulsewidth(cnowarg); + servo2.pulsewidth(cnowarg); + led =1; + }else if (value ==0){ + nowarg = 0;//0を受信した時 + cnowarg = calc(nowarg); + servo1.pulsewidth(cnowarg); + servo2.pulsewidth(cnowarg); + led =0; + } + } + //Xbeeの送信 + xbee.printf("Status%f\r\n",nowarg); + } +}