ECE 4180 Laser Tag

Dependencies:   Motordriver mbed SDFileSystem mbed-rtos wave_player

Committer:
suyash95
Date:
Thu Apr 14 15:25:03 2016 +0000
Revision:
0:4953f3704bb8
Child:
1:6a78c0e371d5
ECE 4180 Robot Laser Tag

Who changed what in which revision?

UserRevisionLine numberNew contents of line
suyash95 0:4953f3704bb8 1 #include "mbed.h"
suyash95 0:4953f3704bb8 2 #include "motordriver.h"
suyash95 0:4953f3704bb8 3 #include "Speaker.h"
suyash95 0:4953f3704bb8 4 Motor m1(p22, p6, p5, 1); // pwm, fwd, rev, can brake left most motor (a)
suyash95 0:4953f3704bb8 5 Motor m2(p23, p7, p8, 1); //right most motor (b)
suyash95 0:4953f3704bb8 6 Speaker mySpeaker(p21);
suyash95 0:4953f3704bb8 7 Serial blue(p13,p14);
suyash95 0:4953f3704bb8 8
suyash95 0:4953f3704bb8 9 DigitalOut reset(p26);
suyash95 0:4953f3704bb8 10 DigitalOut led1(LED1);
suyash95 0:4953f3704bb8 11 DigitalOut led2(LED2);
suyash95 0:4953f3704bb8 12 DigitalOut led3(LED3);
suyash95 0:4953f3704bb8 13 DigitalOut led4(LED4);
suyash95 0:4953f3704bb8 14
suyash95 0:4953f3704bb8 15 int main() {
suyash95 0:4953f3704bb8 16 while(1) {
suyash95 0:4953f3704bb8 17 char bnum=0;
suyash95 0:4953f3704bb8 18 char bhit=0;
suyash95 0:4953f3704bb8 19 if (blue.getc()=='!') {
suyash95 0:4953f3704bb8 20 if (blue.getc()=='B') { //button data packet
suyash95 0:4953f3704bb8 21 bnum = blue.getc(); //button number
suyash95 0:4953f3704bb8 22 bhit = blue.getc(); //1=hit, 0=release
suyash95 0:4953f3704bb8 23 if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK?
suyash95 0:4953f3704bb8 24 switch (bnum) {
suyash95 0:4953f3704bb8 25 case '1': //number button 1
suyash95 0:4953f3704bb8 26 if (bhit=='1') {
suyash95 0:4953f3704bb8 27 led1 = 1;//add hit code here
suyash95 0:4953f3704bb8 28 } else {
suyash95 0:4953f3704bb8 29 led1 = 0;//add release code here
suyash95 0:4953f3704bb8 30 }
suyash95 0:4953f3704bb8 31 break;
suyash95 0:4953f3704bb8 32 case '2': //number button 2
suyash95 0:4953f3704bb8 33 if (bhit=='1') {
suyash95 0:4953f3704bb8 34 led2 = 1;//add hit code here
suyash95 0:4953f3704bb8 35 } else {
suyash95 0:4953f3704bb8 36 led2 = 0;//add release code here
suyash95 0:4953f3704bb8 37 }
suyash95 0:4953f3704bb8 38 break;
suyash95 0:4953f3704bb8 39 case '3': //number button 3
suyash95 0:4953f3704bb8 40 if (bhit=='1') {
suyash95 0:4953f3704bb8 41 led3 = 1;//add hit code here
suyash95 0:4953f3704bb8 42 } else {
suyash95 0:4953f3704bb8 43 led3 = 0;//add release code here
suyash95 0:4953f3704bb8 44 }
suyash95 0:4953f3704bb8 45 break;
suyash95 0:4953f3704bb8 46 case '4': //number button 4
suyash95 0:4953f3704bb8 47 if (bhit=='1') {
suyash95 0:4953f3704bb8 48 led4 = 1;//add hit code here
suyash95 0:4953f3704bb8 49 } else {
suyash95 0:4953f3704bb8 50 led4 = 0;//add release code here
suyash95 0:4953f3704bb8 51 }
suyash95 0:4953f3704bb8 52 break;
suyash95 0:4953f3704bb8 53 case '5': //button 5 up arrow
suyash95 0:4953f3704bb8 54 if (bhit=='1') {
suyash95 0:4953f3704bb8 55 m1.speed(1.0);
suyash95 0:4953f3704bb8 56 m2.speed(1.0);
suyash95 0:4953f3704bb8 57 } else {
suyash95 0:4953f3704bb8 58 m1.speed(0.0);
suyash95 0:4953f3704bb8 59 m2.speed(0.0);
suyash95 0:4953f3704bb8 60 //add release code here
suyash95 0:4953f3704bb8 61 }
suyash95 0:4953f3704bb8 62 break;
suyash95 0:4953f3704bb8 63 case '6': //button 6 down arrow
suyash95 0:4953f3704bb8 64 if (bhit=='1') {
suyash95 0:4953f3704bb8 65 //add hit code here
suyash95 0:4953f3704bb8 66 m1.speed(-1.0);
suyash95 0:4953f3704bb8 67 m2.speed(-1.0);
suyash95 0:4953f3704bb8 68 } else {
suyash95 0:4953f3704bb8 69 m1.speed(0.0);
suyash95 0:4953f3704bb8 70 m2.speed(0.0);
suyash95 0:4953f3704bb8 71 //add release code here
suyash95 0:4953f3704bb8 72 }
suyash95 0:4953f3704bb8 73 break;
suyash95 0:4953f3704bb8 74 case '7': //button 7 left arrow
suyash95 0:4953f3704bb8 75 if (bhit=='1') {
suyash95 0:4953f3704bb8 76 m1.speed(-1.0);
suyash95 0:4953f3704bb8 77 m2.speed(1.0);
suyash95 0:4953f3704bb8 78 //add hit code here
suyash95 0:4953f3704bb8 79 } else {
suyash95 0:4953f3704bb8 80 m1.speed(0.0);
suyash95 0:4953f3704bb8 81 m2.speed(0.0);
suyash95 0:4953f3704bb8 82 //add release code here
suyash95 0:4953f3704bb8 83 }
suyash95 0:4953f3704bb8 84 break;
suyash95 0:4953f3704bb8 85 case '8': //button 8 right arrow
suyash95 0:4953f3704bb8 86 if (bhit=='1') {
suyash95 0:4953f3704bb8 87 //add hit code here
suyash95 0:4953f3704bb8 88 m1.speed(1.0);
suyash95 0:4953f3704bb8 89 m2.speed(-1.0);
suyash95 0:4953f3704bb8 90 } else {
suyash95 0:4953f3704bb8 91 m1.speed(0.0);
suyash95 0:4953f3704bb8 92 m2.speed(0.0);
suyash95 0:4953f3704bb8 93 //add release code here
suyash95 0:4953f3704bb8 94 }
suyash95 0:4953f3704bb8 95 break;
suyash95 0:4953f3704bb8 96 default:
suyash95 0:4953f3704bb8 97 break;
suyash95 0:4953f3704bb8 98 }
suyash95 0:4953f3704bb8 99 }
suyash95 0:4953f3704bb8 100 }
suyash95 0:4953f3704bb8 101 }
suyash95 0:4953f3704bb8 102 }
suyash95 0:4953f3704bb8 103 }