![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Blue
Fork of Motor_HelloWorld by
main.cpp
- Committer:
- bdragon52
- Date:
- 2017-11-14
- Revision:
- 1:294379552123
- Parent:
- 0:7bbc230e00d6
File content as of revision 1:294379552123:
// Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0) #include "mbed.h" #include "Motor.h" //int main() { // for (float s= -1.0; s < 1.0 ; s += 0.01) { // RW.speed(s); // wait(0.02); // } //} BusOut myled(LED1,LED2,LED3,LED4); Serial blue(p28,p27); Motor RW(p24, p12, p13); // pwm, fwd, rev int main() { char bnum=0; char bhit=0; while(1) { if (blue.getc()=='!') { if (blue.getc()=='B') { //button data packet bnum = blue.getc(); //button number bhit = blue.getc(); //1=hit, 0=release if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK? myled = bnum - '0'; //current button number will appear on LEDs switch (bnum) { case '1': //number button 1 if (bhit=='1') { RW.speed(1); //add hit code here } else { //add release code here } break; case '2': //number button 2 if (bhit=='1') { RW.speed(0); //add hit code here } else { //add release code here } break; case '3': //number button 3 if (bhit=='1') { //add hit code here } else { //add release code here } break; case '4': //number button 4 if (bhit=='1') { //add hit code here } else { //add release code here } break; case '5': //button 5 up arrow if (bhit=='1') { //add hit code here RW.speed(1); } else { RW.speed(0); //add release code here } break; case '6': //button 6 down arrow if (bhit=='1') { RW.speed(-1); //add hit code here } else { RW.speed(0); //add release code here } break; case '7': //button 7 left arrow if (bhit=='1') { //add hit code here } else { //add release code here } break; case '8': //button 8 right arrow if (bhit=='1') { //add hit code here } else { //add release code here } break; default: break; } } } } } }