lab3_part2

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

Dependents:   4180_Lab3_rtos_basic FINAL_PROJECT_GAMMA_PROTECTOR

Fork of rtos_basic by mbed official

Files at this revision

API Documentation at this revision

Comitter:
ycai47
Date:
Thu Oct 01 20:35:16 2015 +0000
Parent:
7:49bfd42cbf6f
Commit message:
part 2 done

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
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
wave_player.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 49bfd42cbf6f -r 8eb653dc6571 4DGL-uLCD-SE.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Thu Oct 01 20:35:16 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
diff -r 49bfd42cbf6f -r 8eb653dc6571 SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Thu Oct 01 20:35:16 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
diff -r 49bfd42cbf6f -r 8eb653dc6571 main.cpp
--- a/main.cpp	Thu Oct 01 19:02:10 2015 +0000
+++ b/main.cpp	Thu Oct 01 20:35:16 2015 +0000
@@ -1,44 +1,86 @@
 #include "mbed.h"
 #include "rtos.h"
+#include "uLCD_4DGL.h"
+#include "SDFileSystem.h"
+#include "wave_player.h"
 
-PwmOut Speaker(p26);
- 
+uLCD_4DGL myLCD(p9, p10, p11);
+Mutex lcd_mutex;
+
 PwmOut RGBLED_r(p23);
 PwmOut RGBLED_g(p22);
 PwmOut RGBLED_b(p21);
 
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+
+AnalogOut Speaker(p18);
+wave_player waver(&Speaker);
+bool  PLAY = true;
+bool  *PlayStopPtr = &PLAY;
+
+int j = 0;
+int k = 0;
+
 void ulcd1_thread(void const *args) {
-    while (true) {
-        
-        }
+    while(true) {
+        lcd_mutex.lock();
+        myLCD.locate(0,0);
+        myLCD.printf("Thread1 status count: %d", j);
+        lcd_mutex.unlock();
+        j++;
+        Thread::wait(150);
+    }
 }
 
 void ulcd2_thread(void const *args) {
-    while (true) {
-        
-        }
+    while(true) {
+        lcd_mutex.lock();
+        myLCD.locate(0,5);
+        myLCD.printf("Thread 2 status count : %d", k);
+        lcd_mutex.unlock();
+        k++;
+        Thread::wait(300);
+    }
 }
 
 void led_thread(void const *args) {
-    while (true) {
+    while(true) {
+        RGBLED_g = 0.0;
         RGBLED_r = 1.0;
-        Thread::wait(1000);
+        RGBLED_b = 0.0;
+        Thread::wait(300);
+        RGBLED_r = 0.0;
+        RGBLED_b = 1.0;
+        Thread::wait(300);
     }
 }
 
 void Speaker_thread(void const *args) {
-    while (true) {
-        
-        }
+    while(true) {
+        FILE *wave_file;
+        wave_file=fopen("/sd/mySound/Siren.wav","r");
+        waver.play(wave_file,PlayStopPtr);
+        fclose(wave_file);
+        Thread::wait(1000);    // wait 1.0s
+    }
 }
  
 int main() {
-    Thread thread(ulcd1_thread);
-    Thread thraed(ulcd2_thread);
-    Thread thread(led_thread);
-    Thread thread(Speaker_thread);
+    
+    myLCD.cls();
+    
+    Thread thread0(ulcd1_thread);
+    Thread thread1(ulcd2_thread);
+    Thread thread2(led_thread);
+    Thread thread3(Speaker_thread);
     
+    Timer t;
+    t.start();
     while (true) {
+        lcd_mutex.lock();
+        myLCD.locate(0,9);
+        myLCD.printf("The time taken was %0.2f seconds\n", t.read());
+        lcd_mutex.unlock();
         Thread::wait(500);
     }
 }
diff -r 49bfd42cbf6f -r 8eb653dc6571 wave_player.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wave_player.lib	Thu Oct 01 20:35:16 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/zchen311/code/wave_player/#353c78110e44