Sound update

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

Committer:
jstephens78
Date:
Sun Dec 04 23:31:28 2022 +0000
Revision:
19:6d9bee043ede
Parent:
17:3517251daf96
Child:
20:73e4f12277bd
Tetris compiles now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jstephens78 0:da114b98e013 1 #include "mbed.h"
dangulo7 1:d8cc5013651e 2 #include "rtos.h"
jstephens78 12:5d913b57da7c 3
jstephens78 12:5d913b57da7c 4 #include "globals.h"
jstephens78 12:5d913b57da7c 5 #include "hockey.h"
jstephens78 12:5d913b57da7c 6
jstephens78 10:f5a84133bd65 7 //#include "Speaker.h"
jstephens78 10:f5a84133bd65 8 #include "SDFileSystem.h"
dangulo7 1:d8cc5013651e 9 #include "uLCD_4DGL.h"
jstephens78 0:da114b98e013 10
jstephens78 19:6d9bee043ede 11 Serial pc(USBTX, USBRX);
jstephens78 19:6d9bee043ede 12 //uLCD_4DGL uLCD(p28, p27, p29);
jstephens78 16:6cf744b2623a 13 uLCD_4DGL uLCD(p9,p10,p30);
jstephens78 17:3517251daf96 14 Mutex uLCD_mutex;
jstephens78 17:3517251daf96 15
jstephens78 16:6cf744b2623a 16 BluefruitController blue(p13,p14);
jstephens78 16:6cf744b2623a 17 BusIn navSwitch(p15, p16, p17, p18, p19);
jstephens78 16:6cf744b2623a 18
jstephens78 16:6cf744b2623a 19 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
dangulo7 2:c85af14a0d53 20
jstephens78 0:da114b98e013 21 DigitalOut myled(LED1);
jstephens78 12:5d913b57da7c 22 //AnalogOut DACout(p20);
jstephens78 16:6cf744b2623a 23 PwmOut Rgb(p23);
jstephens78 16:6cf744b2623a 24 PwmOut rGb(p24);
jstephens78 16:6cf744b2623a 25 PwmOut rgB(p25);
jstephens78 16:6cf744b2623a 26 PwmOut PWMout(p21);
jstephens78 12:5d913b57da7c 27 //wave_player waver(&DACout);
jstephens78 12:5d913b57da7c 28
jstephens78 0:da114b98e013 29
dangulo7 1:d8cc5013651e 30 volatile bool game1 = false;
dangulo7 1:d8cc5013651e 31 volatile bool game2 = false;
jstephens78 12:5d913b57da7c 32 /*
jstephens78 11:e00a208bd85a 33 void thread3(void const *argument)
jstephens78 11:e00a208bd85a 34 {
dangulo7 1:d8cc5013651e 35 FILE *wave_file;
jstephens78 11:e00a208bd85a 36 PWMout.period(1.0/400000.0);
jstephens78 11:e00a208bd85a 37 while (game1 == false && game2 == false) {
dangulo7 3:7886a3097c0c 38 wave_file=fopen("/sd/MiiMenu.wav","r");
dangulo7 1:d8cc5013651e 39 waver.play(wave_file);
dangulo7 1:d8cc5013651e 40 fclose(wave_file);
dangulo7 1:d8cc5013651e 41 }
jstephens78 11:e00a208bd85a 42 while (game1 == true && game2 == false) {
dangulo7 3:7886a3097c0c 43 wave_file=fopen("/sd/tetris.wav","r");
dangulo7 1:d8cc5013651e 44 waver.play(wave_file);
dangulo7 1:d8cc5013651e 45 fclose(wave_file);
dangulo7 1:d8cc5013651e 46 }
jstephens78 11:e00a208bd85a 47 while (game2 == true && game1 == false) {
dangulo7 3:7886a3097c0c 48 wave_file=fopen("/sd/WiiPlayAirHockey.wav","r");
dangulo7 1:d8cc5013651e 49 waver.play(wave_file);
dangulo7 1:d8cc5013651e 50 fclose(wave_file);
dangulo7 1:d8cc5013651e 51 }
dangulo7 1:d8cc5013651e 52 }
jstephens78 16:6cf744b2623a 53 */
dangulo7 1:d8cc5013651e 54
jstephens78 11:e00a208bd85a 55 void thread4(void const *argument)
jstephens78 11:e00a208bd85a 56 {
jstephens78 16:6cf744b2623a 57 /*
jstephens78 11:e00a208bd85a 58 float x = 0.0;
dangulo7 1:d8cc5013651e 59 while(1) {
dangulo7 1:d8cc5013651e 60 //get a new random number for PWM
dangulo7 1:d8cc5013651e 61 x = rand() / float(RAND_MAX);
dangulo7 1:d8cc5013651e 62 //add some exponential brightness scaling
dangulo7 1:d8cc5013651e 63 //for more of a fast flash effect
dangulo7 1:d8cc5013651e 64 x = x*x*x;
dangulo7 1:d8cc5013651e 65 Rgb = x;
jstephens78 11:e00a208bd85a 66 rGb = x;
jstephens78 11:e00a208bd85a 67 rgB = x;
dangulo7 1:d8cc5013651e 68 //fast update rate for welding flashes
dangulo7 1:d8cc5013651e 69 Thread::wait(20);
dangulo7 1:d8cc5013651e 70 //add a random pause between welds
jstephens78 11:e00a208bd85a 71 if (rand() / float(RAND_MAX) > 0.95) {
dangulo7 1:d8cc5013651e 72 Rgb = 0;
dangulo7 1:d8cc5013651e 73 rGb = 0;
dangulo7 1:d8cc5013651e 74 rgB = 0;
dangulo7 1:d8cc5013651e 75 Thread::wait(4000.0 * rand() / float(RAND_MAX));
dangulo7 1:d8cc5013651e 76 }
jstephens78 11:e00a208bd85a 77 }
jstephens78 16:6cf744b2623a 78 */
dangulo7 1:d8cc5013651e 79 }
jstephens78 16:6cf744b2623a 80
jstephens78 11:e00a208bd85a 81 int main()
jstephens78 11:e00a208bd85a 82 {
jstephens78 12:5d913b57da7c 83 printf("Starting thread 2\r\n");
jstephens78 12:5d913b57da7c 84 game2 = true;
jstephens78 12:5d913b57da7c 85 Thread thread2(hockeyGame);
jstephens78 12:5d913b57da7c 86 //Thread thread3(thread3);
jstephens78 16:6cf744b2623a 87 // Thread thread4(thread4);
jstephens78 16:6cf744b2623a 88
jstephens78 12:5d913b57da7c 89 while (true) {
jstephens78 0:da114b98e013 90 myled = 1;
jstephens78 12:5d913b57da7c 91 Thread::wait(500);
jstephens78 0:da114b98e013 92 myled = 0;
jstephens78 12:5d913b57da7c 93 Thread::wait(500);
jstephens78 0:da114b98e013 94 }
jstephens78 0:da114b98e013 95 }