ECE 4180 Laser Tag
Dependencies: Motordriver mbed SDFileSystem mbed-rtos wave_player
main.cpp
- Committer:
- suyash95
- Date:
- 2016-04-14
- Revision:
- 0:4953f3704bb8
- Child:
- 1:6a78c0e371d5
File content as of revision 0:4953f3704bb8:
#include "mbed.h" #include "motordriver.h" #include "Speaker.h" Motor m1(p22, p6, p5, 1); // pwm, fwd, rev, can brake left most motor (a) Motor m2(p23, p7, p8, 1); //right most motor (b) Speaker mySpeaker(p21); Serial blue(p13,p14); DigitalOut reset(p26); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); int main() { while(1) { char bnum=0; char bhit=0; 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? switch (bnum) { case '1': //number button 1 if (bhit=='1') { led1 = 1;//add hit code here } else { led1 = 0;//add release code here } break; case '2': //number button 2 if (bhit=='1') { led2 = 1;//add hit code here } else { led2 = 0;//add release code here } break; case '3': //number button 3 if (bhit=='1') { led3 = 1;//add hit code here } else { led3 = 0;//add release code here } break; case '4': //number button 4 if (bhit=='1') { led4 = 1;//add hit code here } else { led4 = 0;//add release code here } break; case '5': //button 5 up arrow if (bhit=='1') { m1.speed(1.0); m2.speed(1.0); } else { m1.speed(0.0); m2.speed(0.0); //add release code here } break; case '6': //button 6 down arrow if (bhit=='1') { //add hit code here m1.speed(-1.0); m2.speed(-1.0); } else { m1.speed(0.0); m2.speed(0.0); //add release code here } break; case '7': //button 7 left arrow if (bhit=='1') { m1.speed(-1.0); m2.speed(1.0); //add hit code here } else { m1.speed(0.0); m2.speed(0.0); //add release code here } break; case '8': //button 8 right arrow if (bhit=='1') { //add hit code here m1.speed(1.0); m2.speed(-1.0); } else { m1.speed(0.0); m2.speed(0.0); //add release code here } break; default: break; } } } } } }