GGController

Dependencies:   BufferedSerial DRV8833 mbed

Fork of HelloWorld by Simon Ford

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "DRV8833.h"
00003 #include "BufferedSerial.h"
00004 
00005 
00006 DigitalOut led1(LED1);
00007 DigitalOut led2(LED2);
00008 DigitalOut led3(LED3);
00009 DigitalOut led4(LED4);
00010  
00011 Serial pc(USBTX, USBRX);
00012 
00013  int err;
00014 DRV8833 motor1(p21,p22);
00015 DRV8833 motor2(p23,p24);
00016 DRV8833 motor3(p25,p26);
00017  
00018 int main() {
00019      pc.baud(115200);
00020      motor1.period(0.0000035f);
00021      motor2.period(0.0000035f);
00022      motor3.period(0.0000035f);
00023      float s1,s2,s3;
00024     while (1) {
00025         if(pc.readable())
00026         {
00027           char c;
00028           err=pc.scanf("%c",&c);
00029           if(c=='t')
00030           {
00031               pc.printf("r\n");
00032             led2 = 1;
00033             wait(0.1);
00034             led2=0;
00035           }else if(c=='d')
00036           {
00037            //  printf("reading bytes\n");
00038              int m1,m2,m3;
00039             err=pc.scanf("%d %d %d",&m1,&m2,&m3);
00040             s1=(float)(m1)/(float)1000.0f;
00041             s2=(float)(m2)/(float)1000.0f;
00042             s3=(float)(m3)/(float)1000.0f;
00043             
00044             motor1.speed(s1);
00045             motor2.speed(s2);
00046             motor3.speed(s3);
00047             
00048            // printf("%f,%f,%f\n",s1,s2,s3);
00049            } 
00050         //    led1 = !led1;
00051         }
00052     }
00053 }