Sound update

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

Committer:
jstephens78
Date:
Thu Dec 01 01:43:39 2022 +0000
Revision:
17:3517251daf96
Parent:
16:6cf744b2623a
Child:
19:6d9bee043ede
Cleaned up air hockey gameplay logic and put uLCD accesses behind mutex locks.

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