ECE 4180 Final

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

Revision:
1:a1aa9a79070a
Parent:
0:4f77ae831ee7
Child:
2:765774781bb1
--- a/main.cpp	Tue Dec 03 21:24:00 2019 +0000
+++ b/main.cpp	Tue Dec 03 22:42:46 2019 +0000
@@ -1,6 +1,3 @@
-// example to test the mbed Lab Board lcd lib with the mbed rtos
-// Pot1 changes the contrast
-// Pot2 changes the speed of the sin wave
 #include "mbed.h"
 #include "SDFileSystem.h"
 #include "wave_player.h"
@@ -98,13 +95,15 @@
 DigitalOut myled(LED1);
 DigitalIn pb1(p20);
 DigitalIn pb2(p19);
+AnalogOut DACout(p18);
+wave_player waver(&DACout);
 
 // mutex to make the lcd lib thread safe
 Mutex lcd_mutex;
 int songnum = 1;
 AnalogIn joy_pot(p16);
 // Thread 1
-// print counter into first line and wait for 1 s
+// print homescreen to LCD
 void thread1(void const *args)
 {
     
@@ -128,45 +127,33 @@
             uLCD.printf("Song3");
             uLCD.rectangle(5, songnum*30, 100, songnum*30+25 ,GREEN);
             lcd_mutex.unlock();
-            if (songselect){
-                myled = 0;
-                homescreen = false;
-                lcd_mutex.lock();
-                uLCD.cls();
-                uLCD.printf("You selected song %2d",songnum);
-                lcd_mutex.unlock();
-                
+            
                 }
-            //FILE *fp = fopen("/sd/sdtest.txt", "r");
-            //char c = fgetc(fp);
-            //while(c){
-            //    c = fgetc(fp);
-            //    }
-            }
             Thread::wait(200);    
     }
 }
 
+//for song selection during homescreen
 void thread2(void const *args)
 {
 
    while(1){
-        //if (homescreen){
+        if (homescreen){
             if ((joy_pot <= (1.4/3.3)) && songnum>1) {
                 songnum--;
                 } 
             else if ((joy_pot >= (1.8/3.3)) && songnum<3){
                 songnum++;
                 }
-        //    }
+            }
         Thread::wait(250);
         
     }
 }
 
 // Thread 3
-// print a sin function in a small window
-// the value of pot 1 changes the speed of the sine wave
+//pb1 is to select song
+//pb2 is to return to homescreen
 void thread3(void const *args)
 {
     pb1.mode(PullUp);
@@ -187,6 +174,8 @@
 
 int main()
 {
+    //doesnt work yet, need to ask hamblen
+
     uLCD.media_init();
     uLCD.set_sector_address(0x001D, 0x4C01);
     uLCD.display_image(0,0);
@@ -195,11 +184,30 @@
 //    t3.start(thread3);
     Thread t1(thread1);
     Thread t2(thread2);
-    myled = 1;
     Thread t3(thread3);
+    //startup sound. Commented out for testing without SD card
+    //FILE *wave_file;
+    //wave_file=fopen("/sd/cheer.wav","r");
+    //waver.play(wave_file);
+    //fclose(wave_file);
     while(1) 
     {
         
+        if (songselect){
+                myled = 0;
+                homescreen = false;
+                lcd_mutex.lock();
+                uLCD.cls();
+                uLCD.printf("You selected song %2d",songnum);
+                lcd_mutex.unlock();
+                //add case statement based on songnum or something
+                //code for playing song from sd
+                //FILE *wave_file;
+                //wave_file=fopen("/sd/sample1.wav","r");
+                //waver.play(wave_file);
+                //fclose(wave_file);
+                //end
+                }
         Thread::wait(100);    
         }
 }