Projet S5 Info - Beginner

Dependencies:   TextLCD XBeeLib mbed-rtos mbed

Fork of Coordinateur-Advanced by Vincent Belanger

Revision:
2:a7820185e9a8
Parent:
1:33b4a3b5cdb5
Child:
4:714484401021
diff -r 33b4a3b5cdb5 -r a7820185e9a8 main.cpp
--- a/main.cpp	Mon Apr 04 18:55:43 2016 +0000
+++ b/main.cpp	Wed Apr 06 14:19:30 2016 +0000
@@ -1,4 +1,5 @@
 #include "mbed.h"
+#include "rtos.h"
 #include "XBeeLib.h"
 #include "SDFileSystem.h"
 #include "wave_player.h"
@@ -6,9 +7,11 @@
 using namespace XBeeLib;
 
 SDFileSystem sd(p5, p6, p7, p8, "sd"); // MOSI, MISO, SCLK, SSEL
-AnalogOut DACout(p18);
-wave_player player(&DACout);
+PwmOut speaker(p21);
+//wave_player player(&DACout);
 Serial pc(USBTX, USBRX);
+osThreadId threadIDC5;
+osThreadId threadIDG5;
 
 bool capt_1;
 bool capt_2;
@@ -44,11 +47,15 @@
     pc.printf("%i ", capt_6);
 
     pc.printf("\r\n");
+    
+    osSignalSet(threadIDC5, 0x1);
+    osSignalSet(threadIDG5, 0x2);
 }
- 
-int main()
+
+void playFile(const char* name)
 {
-    FILE *fp = fopen("/sd/Synth/A5.wav", "r");
+    /*
+    FILE *fp = fopen(name, "r");
     if(fp == NULL) {
         pc.printf("Could not open file for read\r\n");
     }
@@ -56,13 +63,48 @@
         player.play(fp);
     }
     fclose(fp);
+    */
+    
+    speaker.period(1.0/500.0); // 500hz period
+    speaker =0.5; //50% duty cycle - max volume
+    wait(3);
+    speaker=0.0; // turn off audio
+    wait(2);
+}
+
+void playC5(void const* args)
+{
+    threadIDC5 = osThreadGetId();
+
+    osSignalWait(0x1, osWaitForever);
+    pc.printf("Wait done C5");
+    playFile("/sd/Synth/C5.wav");
+}
+
+void playG5(void const* args)
+{
+    threadIDG5 = osThreadGetId();
+
+    osSignalWait(0x2, osWaitForever);
+    pc.printf("Wait done G5");
+    //wait(1);
+    //playFile("/sd/Synth/A5.wav");
+}
+
+int main()
+{
+    Thread C5(playC5);
+    //C5.set_priority(osPriorityHigh);
+    Thread G5(playG5);
+    //G5.set_priority(osPriorityHigh);
 
     XBeeZB xbee = XBeeZB(p13, p14, p8, NC, NC, 9600);
- 
+
     /* Register callbacks */
     xbee.register_receive_cb(&receive_cb);
- 
+
     RadioStatus const radioStatus = xbee.init();
+
     MBED_ASSERT(radioStatus == Success);
  
     /* Wait until the device has joined the network */
@@ -74,6 +116,6 @@
  
     while (true) {
         xbee.process_rx_frames();
-        wait_ms(100);
+        wait_ms(2000);
     }
 }