bluetooth

Dependencies:   4DGL-uLCD-SE SDFileSystem_3 mbed-rtos mbed wave_player

Files at this revision

API Documentation at this revision

Comitter:
mus3
Date:
Thu Oct 13 18:59:26 2022 +0000
Parent:
1:60087ee45d3b
Child:
3:0bc0b28da20d
Commit message:
lab3part5 bluetooth

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SDFileSystem.lib	Thu Oct 13 18:11:15 2022 +0000
+++ b/SDFileSystem.lib	Thu Oct 13 18:59:26 2022 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/SDFileSystem/#f86bde1d12eb
+http://mbed.org/users/mbed_official/code/SDFileSystem/#9cb3ff167f15
--- a/main.cpp	Thu Oct 13 18:11:15 2022 +0000
+++ b/main.cpp	Thu Oct 13 18:59:26 2022 +0000
@@ -9,6 +9,7 @@
 PwmOut RGBLED_r(p23);
 PwmOut RGBLED_g(p24);
 PwmOut RGBLED_b(p25);
+Serial blue(p13,p14);
 
 float note[18]= {1568.0,1396.9,1244.5,1244.5,1396.9,1568.0,1568.0,1568.0,1396.9,
                  1244.5,1396.9,1568.0,1396.9,1244.5,1174.7,1244.5,1244.5, 0.0
@@ -23,6 +24,9 @@
 // global variables
 int i = 0;
 int ix = 0;
+int iy = 90;
+char color = 'g';
+int flight_dir = 8;
 
 void drawairplane(int x, int y) {
     uLCD.filled_rectangle(x, y+7, x+27, y+13, WHITE);
@@ -41,6 +45,7 @@
 void thread1(void const *args)
 {
     while(true) {         // thread loop
+        /*
         if (i < 10) {
             RGBLED_r = 0.0;
             RGBLED_g = (float) i / 10;
@@ -61,6 +66,24 @@
             i = -1;
         }
         i++;
+        */
+        if (color == 'r') {
+            RGBLED_r = 0.8;
+            RGBLED_g = 0.0;
+            RGBLED_b = 0.0;
+        } else if (color == 'g') {
+            RGBLED_r = 0.0;
+            RGBLED_g = 0.8;
+            RGBLED_b = 0.0;
+        } else if (color == 'b') {
+            RGBLED_r = 0.0;
+            RGBLED_g = 0.0;
+            RGBLED_b = 0.8;
+        } else {
+            RGBLED_r = 0.0;
+            RGBLED_g = 0.8;
+            RGBLED_b = 0.0;
+        }
         Thread::wait(200);    // wait 0.2s
     }
 }
@@ -96,11 +119,25 @@
     while (true) {
         lcd_mutex.lock();
         uLCD.filled_rectangle(0, 63, 127, 127, BLACK);
-        drawairplane(ix, 90);
+        drawairplane(ix, iy);
         lcd_mutex.unlock();
-        ix += 1;
+        if (flight_dir == 8) {
+            ix += 1;
+        } else if (flight_dir == 7) {
+            ix -= 1;
+        } else if (flight_dir == 6) {
+            iy += 1;
+        } else if (flight_dir == 5) {
+            iy -= 1;
+        }
         if (ix > 100) {
             ix = 0;
+        } else if (ix < 0) {
+            ix = 99;
+        } else if (iy > 113) {
+            iy = 64;
+        } else if (iy < 64) {
+            iy = 113;
         }
         Thread::wait(500);    // wait 0.75s
     }
@@ -114,10 +151,87 @@
     Thread t4(thread4); //start thread3
     set_time(1256729737);
     while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+        char bnum=0;
+        char bhit=0;
+        if (!blue.readable()) {
+            continue;
+        }
+        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') {
+                                //add hit code here
+                                color = 'r';
+                            } //else {
+                                //add release code here
+                            //}
+                            break;
+                        case '2': //number button 2
+                            if (bhit=='1') {
+                                //add hit code here
+                                color = 'g';
+                            } //else {
+                                //add release code here
+                            //}
+                            break;
+                        case '3': //number button 3
+                            if (bhit=='1') {
+                                //add hit code here
+                                color = 'b';
+                            } //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
+                                flight_dir = 5;
+                            } //else {
+                                //add release code here
+                            //}
+                            break;
+                        case '6': //button 6 down arrow
+                            if (bhit=='1') {
+                                //add hit code here
+                                flight_dir = 6;
+                            } //else {
+                                //add release code here
+                            //}
+                            break;
+                        case '7': //button 7 left arrow
+                            if (bhit=='1') {
+                                //add hit code here
+                                flight_dir = 7;
+                            } //else {
+                                //add release code here
+                            //}
+                            break;
+                        case '8': //button 8 right arrow
+                            if (bhit=='1') {
+                                //add hit code here
+                                flight_dir = 8;
+                            } //else {
+                                //add release code here
+                            //}
+                            break;
+                        default:
+                            break;
+                    }
+                }
+            }
+        }
     }
     Thread::wait(200);    // wait 0.2s
 }