GGController
Dependencies: BufferedSerial DRV8833 mbed
Fork of HelloWorld by
Diff: main.cpp
- Revision:
- 2:375e29585498
- Parent:
- 0:fb6bbc10ffa0
--- a/main.cpp Sun Jan 01 20:57:57 2012 +0000 +++ b/main.cpp Tue Oct 20 08:35:55 2015 +0000 @@ -1,12 +1,53 @@ #include "mbed.h" +#include "DRV8833.h" +#include "BufferedSerial.h" + -DigitalOut myled(LED1); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +Serial pc(USBTX, USBRX); + int err; +DRV8833 motor1(p21,p22); +DRV8833 motor2(p23,p24); +DRV8833 motor3(p25,p26); + int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + pc.baud(115200); + motor1.period(0.0000035f); + motor2.period(0.0000035f); + motor3.period(0.0000035f); + float s1,s2,s3; + while (1) { + if(pc.readable()) + { + char c; + err=pc.scanf("%c",&c); + if(c=='t') + { + pc.printf("r\n"); + led2 = 1; + wait(0.1); + led2=0; + }else if(c=='d') + { + // printf("reading bytes\n"); + int m1,m2,m3; + err=pc.scanf("%d %d %d",&m1,&m2,&m3); + s1=(float)(m1)/(float)1000.0f; + s2=(float)(m2)/(float)1000.0f; + s3=(float)(m3)/(float)1000.0f; + + motor1.speed(s1); + motor2.speed(s2); + motor3.speed(s3); + + // printf("%f,%f,%f\n",s1,s2,s3); + } + // led1 = !led1; + } } -} +} \ No newline at end of file