This program is a part of Lab Assignment to introduce mbedRTOS feature. It has four threads.

Dependencies:   4DGL-uLCD-SE wave_player_appbd

Fork of rtos_mutex by mbed official

This program is a part of a ECE4180 Lab3. It uses four threads. Main thread is for counting the RTC time and printing to uLCD. Anohter thread is for playing short tone, next is for displaying image in uLCD from the unformatted SD card. Next thread control the RBG led. All these threads utilize bluetooth serial UART command received and function accordingly. Bluetooth App from adafruit is used as an assistance to send command.

Parts used: mBED LPC1768 uLCD Display + SD Card Adafruit Bluetooth Audio Amp + Speaker

Files at this revision

API Documentation at this revision

Comitter:
pkoirala3
Date:
Sat Mar 18 13:55:08 2017 +0000
Parent:
7:4ba0bb973eb9
Commit message:
Formatted code

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Mar 18 13:50:28 2017 +0000
+++ b/main.cpp	Sat Mar 18 13:55:08 2017 +0000
@@ -18,21 +18,22 @@
 
 Speaker mySpeaker(p25);
 
-void threat1RGB(){
+void threat1RGB()
+{
     char bred=0;
     char bgreen=0;
     char bblue=0;
     red = green = blue = 0;
-    while(1){
-        if(bluemod.readable()){
+    while(1) {
+        if(bluemod.readable()) {
             uLCDmutex.lock();
-            if (bluemod.getc()=='!'){
-                if (bluemod.getc()=='C'){ //color data packet
+            if (bluemod.getc()=='!') {
+                if (bluemod.getc()=='C') { //color data packet
                     printf("Color Packet Recieved\r\n");
                     bred = bluemod.getc(); // RGB color values
                     bgreen = bluemod.getc();
                     bblue = bluemod.getc();
-                    if (bluemod.getc()==char(~('!' + 'C' + bred + bgreen + bblue))){ //checksum OK?
+                    if (bluemod.getc()==char(~('!' + 'C' + bred + bgreen + bblue))) { //checksum OK?
                         printf("valid checksum, LED changing\r\n");
                         red = bred/255.0; //send new color to RGB LED PWM outputs
                         green = bgreen/255.0;
@@ -46,17 +47,17 @@
     }
 }
 
-void thread2image(){
-    while(1){
-        while(bluemod.readable()){
+void thread2image()
+{
+    while(1) {
+        while(bluemod.readable()) {
             uLCDmutex.lock();
-            if(bluemod.getc() == '1'){
+            if(bluemod.getc() == '1') {
                 printf("Image Displaying\r\n");
                 uLCD.media_init();
                 uLCD.set_sector_address(0x0000, 0x0000);
                 uLCD.display_image(0,0);
-            }
-            else if(bluemod.getc() == '2'){
+            } else if(bluemod.getc() == '2') {
                 printf("Clear Screen\r\n");
                 uLCD.cls();
             }
@@ -66,7 +67,8 @@
     }
 }
 
-void thread3Audio(){
+void thread3Audio()
+{
     float D41 = 293.665;
     float Eb4 = 311.127;
     float F4 = 349.228;
@@ -74,41 +76,37 @@
     float len = 0.40;
     float note[18]= {G4, F4, Eb4, Eb4, Eb4, F4, G4, G4, G4, F4, Eb4, F4, G4, F4, Eb4, D41, Eb4, 0.0};
     float dur[18]= {len, 0.5*len, len, 0.5*len, len, 0.5*len, len, len, 0.5*len, 0.5*len, 0.5*len, 0.5*len, 0.5*len,0.5*len, 1*len, 0.5*len, 1.5*len, 0.0};
-    int playFlag = 0;        
-    
-    while(1){
-        while(bluemod.readable()){
+    int playFlag = 0;
+
+    while(1) {
+        while(bluemod.readable()) {
             uLCDmutex.lock();
-            if(bluemod.getc() == '3'){
-                printf("Playing Audio\r\n");  
+            if(bluemod.getc() == '3') {
+                printf("Playing Audio\r\n");
                 playFlag = 1;
             }
             uLCDmutex.unlock();
-            if(playFlag == 1){
-                for(int i = 0; i < 18; ++i) {mySpeaker.PlayNote(note[i],dur[i],0.5); }
+            if(playFlag == 1) {
+                for(int i = 0; i < 18; ++i) {
+                    mySpeaker.PlayNote(note[i],dur[i],0.5);
+                }
                 playFlag = 0;
             }
             Thread::wait(500);
         }
-    }       
-}     
+    }
+}
 
-int main(){
+int main()
+{
     uLCD.cls();
     uLCD.baudrate(3000000); //jack up baud rate to max for fast display
     t1.start(threat1RGB);
     t2.start(thread2image);
     t3.start(thread3Audio);
-    while(1);
-}
-
-
-
-
-/*
     set_time(0);  // Set RTC time to 0
-    char buffer[32]; 
-    while(1){
+    char buffer[32];
+    while(1) {
         time_t seconds = time(NULL);
         strftime(buffer, 32, "%M:%S", localtime(&seconds));
         uLCDmutex.lock();
@@ -119,4 +117,4 @@
         uLCDmutex.unlock();
         Thread::wait(500);
     }
-    */
\ No newline at end of file
+}