Lab 3 Part 4

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

Revision:
14:ae63fb7c2d06
Parent:
13:8987c75dfe41
Child:
15:e406620ee8af
--- a/main.cpp	Thu Feb 25 19:18:25 2021 +0000
+++ b/main.cpp	Thu Feb 25 20:51:58 2021 +0000
@@ -5,8 +5,6 @@
 #include "SDFileSystem.h"
 #include "wave_player.h"
 
-InterruptIn data(p14);
-
 char setting = '1';
 
 BusOut myled(LED1,LED2,LED3,LED4);
@@ -20,6 +18,7 @@
 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
 
 Mutex stdio_mutex;
+Mutex get_mutex;
 
 uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin;
 
@@ -32,6 +31,16 @@
 Thread thread3;
 Thread thread4;
 
+Semaphore sem1(0);
+Semaphore sem2(0);
+
+///* The Terminator 53. Coming to theatres this summer!!!!!! */
+//void the_terminator()
+//{
+//
+//}
+
+
 /* Function Calls */
 void top_red_box()
 {
@@ -59,23 +68,10 @@
     stdio_mutex.unlock();
 }
 
-/* Interrupt */
-void set()
-{
-    char bnum;
-    if (blue.readable() && blue.getc()=='!') {
-        if (blue.getc()=='B') { //button data
-            bnum = blue.getc(); //button number
-            if ((bnum>='1')&&(bnum<='4')) //is a number button 1..4
-                setting = bnum;// Set new setting
-        }
-    }
-}
 
 /* Threads */
 void led_thread()
 {
-    //char bnum = setting;
     while(1) {
         if(setting == '1') {
             bLED = 0;
@@ -97,6 +93,20 @@
             gLED = 1;
             Thread::wait(750);
         }
+        if (blue.readable() && blue.getc()=='!') {
+            if (blue.getc()=='B') { //button data
+                char bnum = blue.getc(); //button number
+                if ((bnum>='1')&&(bnum<='4')) { //is a number button 1..4
+                    setting = bnum;// Change setting based on button input to set start setting. Check for chars
+                    rLED = 0;
+                    gLED = 0;
+                    bLED = 0;
+                    myled[bnum-'1']=blue.getc()-'0'; //turn on/off that num LED
+                    wait(1);
+                    break;
+                }
+            }
+        }
     }
 }
 
@@ -104,7 +114,6 @@
 {
     while(1) {
         FILE *wave_file;
-        printf("\n\n\nHello, wave world!\n");
         wave_file=fopen("/sd/WEEWOO.wav","r");
         waver.play(wave_file);
         fclose(wave_file);
@@ -137,6 +146,7 @@
     gLED = 0;
     bLED = 0;
 
+    /* Wait for user to press a setting button */
     char bnum=0;
     while(1) {
         if (blue.readable() && blue.getc()=='!') {
@@ -148,17 +158,27 @@
                 }
             }
         }
+    }
 
-    }
-    
-    
-    //data.rise(&set);
-
+    /* Start all threads */
     thread1.start(led_thread);
     thread2.start(speaker_thread);
     thread3.start(lcd1_thread);
     thread4.start(lcd2_thread);
 
+    /* Infinite Loop, let threads run */
     while (true) {
+        ///* Terminate all thread processes */
+//        thread1.join();
+//
+//        thread2.terminate();
+//        thread3.terminate();
+//        thread4.terminate();
+//
+//        /* Start all thread processes again, this time with new settings */
+//        thread1.start(led_thread);
+//        thread2.start(speaker_thread);
+//        thread3.start(lcd1_thread);
+//        thread4.start(lcd2_thread);
     }
 }