Sound update

Dependencies:   4DGL-uLCD-SE Physac-MBED PinDetect SDFileSystem mbed-rtos mbed

Revision:
1:d8cc5013651e
Parent:
0:da114b98e013
Child:
2:c85af14a0d53
--- a/main.cpp	Mon Nov 14 20:23:43 2022 +0000
+++ b/main.cpp	Tue Nov 29 21:08:00 2022 +0000
@@ -1,8 +1,70 @@
 #include "mbed.h"
+#include "rtos.h"
+#include "wave_player.h"
+#include "Speaker.h"
+#include "uLCD_4DGL.h"
 
+SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
+wave_player waver(&DACout,&PWMout);
 DigitalOut myled(LED1);
+AnalogOut DACout(p20);
+PwmOut Rgb(p23);
+PwmOut rGb(p24);
+PwmOut rgB(p25);
+PwmOut PWMout(p21);
 
+volatile bool game1 = false;
+volatile bool game2 = false;
+
+void thread2(void const *argument){
+
+}
+
+void thread3(void const *argument){
+    FILE *wave_file;
+    PWNout.period(1.0/400000.0);
+    while (game1 == false && game2 == false){
+        wave_file=fopen("/sd/placeholder.wav","r");
+        waver.play(wave_file);
+        fclose(wave_file);
+    }
+    while (game1 == true && game2 == false){
+        wave_file=fopen("/sd/placeholder.wav","r");
+        waver.play(wave_file);
+        fclose(wave_file);
+    }
+    while (game2 == true && game1 == false){
+        wave_file=fopen("/sd/placeholder.wav","r");
+        waver.play(wave_file);
+        fclose(wave_file);
+    }
+}
+
+void thread4(void const *argument){
+    while(1) {
+        float x = 0.0;
+        //get a new random number for PWM
+        x = rand() / float(RAND_MAX);
+        //add some exponential brightness scaling
+        //for more of a fast flash effect
+        x = x*x*x;
+        Rgb = x;
+        rGb = x * dim;
+        rgB = x * dim;
+        //fast update rate for welding flashes
+        Thread::wait(20);
+        //add a random pause between welds
+        if (rand() / float(RAND_MAX) > 0.97) {
+            Rgb = 0;
+            rGb = 0;
+            rgB = 0;
+            Thread::wait(4000.0 * rand() / float(RAND_MAX));
+        }
+}
 int main() {
+    Thread thread2(thread2);
+    Thread thread3(thread3);
+    Thread thread4(thread4);
     while(1) {
         myled = 1;
         wait(0.2);