Sound update
Dependencies: 4DGL-uLCD-SE Physac-MBED PinDetect SDFileSystem mbed-rtos mbed
main.cpp@10:f5a84133bd65, 23 months ago (annotated)
- Committer:
- jstephens78
- Date:
- Tue Nov 29 22:51:16 2022 +0000
- Revision:
- 10:f5a84133bd65
- Parent:
- 3:7886a3097c0c
- Child:
- 11:e00a208bd85a
Add include for sdfilesystem
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jstephens78 | 0:da114b98e013 | 1 | #include "mbed.h" |
dangulo7 | 1:d8cc5013651e | 2 | #include "rtos.h" |
dangulo7 | 1:d8cc5013651e | 3 | #include "wave_player.h" |
jstephens78 | 10:f5a84133bd65 | 4 | //#include "Speaker.h" |
jstephens78 | 10:f5a84133bd65 | 5 | #include "SDFileSystem.h" |
dangulo7 | 1:d8cc5013651e | 6 | #include "uLCD_4DGL.h" |
jstephens78 | 0:da114b98e013 | 7 | |
dangulo7 | 1:d8cc5013651e | 8 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board |
dangulo7 | 2:c85af14a0d53 | 9 | |
jstephens78 | 0:da114b98e013 | 10 | DigitalOut myled(LED1); |
dangulo7 | 1:d8cc5013651e | 11 | AnalogOut DACout(p20); |
dangulo7 | 1:d8cc5013651e | 12 | PwmOut Rgb(p23); |
dangulo7 | 1:d8cc5013651e | 13 | PwmOut rGb(p24); |
dangulo7 | 1:d8cc5013651e | 14 | PwmOut rgB(p25); |
dangulo7 | 1:d8cc5013651e | 15 | PwmOut PWMout(p21); |
dangulo7 | 2:c85af14a0d53 | 16 | wave_player waver(&DACout,&PWMout); |
jstephens78 | 0:da114b98e013 | 17 | |
dangulo7 | 1:d8cc5013651e | 18 | volatile bool game1 = false; |
dangulo7 | 1:d8cc5013651e | 19 | volatile bool game2 = false; |
dangulo7 | 1:d8cc5013651e | 20 | |
dangulo7 | 1:d8cc5013651e | 21 | void thread2(void const *argument){ |
dangulo7 | 1:d8cc5013651e | 22 | |
dangulo7 | 1:d8cc5013651e | 23 | } |
dangulo7 | 1:d8cc5013651e | 24 | |
dangulo7 | 1:d8cc5013651e | 25 | void thread3(void const *argument){ |
dangulo7 | 1:d8cc5013651e | 26 | FILE *wave_file; |
dangulo7 | 1:d8cc5013651e | 27 | PWNout.period(1.0/400000.0); |
dangulo7 | 1:d8cc5013651e | 28 | while (game1 == false && game2 == false){ |
dangulo7 | 3:7886a3097c0c | 29 | wave_file=fopen("/sd/MiiMenu.wav","r"); |
dangulo7 | 1:d8cc5013651e | 30 | waver.play(wave_file); |
dangulo7 | 1:d8cc5013651e | 31 | fclose(wave_file); |
dangulo7 | 1:d8cc5013651e | 32 | } |
dangulo7 | 1:d8cc5013651e | 33 | while (game1 == true && game2 == false){ |
dangulo7 | 3:7886a3097c0c | 34 | wave_file=fopen("/sd/tetris.wav","r"); |
dangulo7 | 1:d8cc5013651e | 35 | waver.play(wave_file); |
dangulo7 | 1:d8cc5013651e | 36 | fclose(wave_file); |
dangulo7 | 1:d8cc5013651e | 37 | } |
dangulo7 | 1:d8cc5013651e | 38 | while (game2 == true && game1 == false){ |
dangulo7 | 3:7886a3097c0c | 39 | wave_file=fopen("/sd/WiiPlayAirHockey.wav","r"); |
dangulo7 | 1:d8cc5013651e | 40 | waver.play(wave_file); |
dangulo7 | 1:d8cc5013651e | 41 | fclose(wave_file); |
dangulo7 | 1:d8cc5013651e | 42 | } |
dangulo7 | 1:d8cc5013651e | 43 | } |
dangulo7 | 1:d8cc5013651e | 44 | |
dangulo7 | 1:d8cc5013651e | 45 | void thread4(void const *argument){ |
dangulo7 | 1:d8cc5013651e | 46 | while(1) { |
dangulo7 | 1:d8cc5013651e | 47 | float x = 0.0; |
dangulo7 | 1:d8cc5013651e | 48 | //get a new random number for PWM |
dangulo7 | 1:d8cc5013651e | 49 | x = rand() / float(RAND_MAX); |
dangulo7 | 1:d8cc5013651e | 50 | //add some exponential brightness scaling |
dangulo7 | 1:d8cc5013651e | 51 | //for more of a fast flash effect |
dangulo7 | 1:d8cc5013651e | 52 | x = x*x*x; |
dangulo7 | 1:d8cc5013651e | 53 | Rgb = x; |
dangulo7 | 1:d8cc5013651e | 54 | rGb = x * dim; |
dangulo7 | 1:d8cc5013651e | 55 | rgB = x * dim; |
dangulo7 | 1:d8cc5013651e | 56 | //fast update rate for welding flashes |
dangulo7 | 1:d8cc5013651e | 57 | Thread::wait(20); |
dangulo7 | 1:d8cc5013651e | 58 | //add a random pause between welds |
dangulo7 | 1:d8cc5013651e | 59 | if (rand() / float(RAND_MAX) > 0.97) { |
dangulo7 | 1:d8cc5013651e | 60 | Rgb = 0; |
dangulo7 | 1:d8cc5013651e | 61 | rGb = 0; |
dangulo7 | 1:d8cc5013651e | 62 | rgB = 0; |
dangulo7 | 1:d8cc5013651e | 63 | Thread::wait(4000.0 * rand() / float(RAND_MAX)); |
dangulo7 | 1:d8cc5013651e | 64 | } |
dangulo7 | 1:d8cc5013651e | 65 | } |
jstephens78 | 0:da114b98e013 | 66 | int main() { |
dangulo7 | 1:d8cc5013651e | 67 | Thread thread2(thread2); |
dangulo7 | 1:d8cc5013651e | 68 | Thread thread3(thread3); |
dangulo7 | 1:d8cc5013651e | 69 | Thread thread4(thread4); |
jstephens78 | 0:da114b98e013 | 70 | while(1) { |
jstephens78 | 0:da114b98e013 | 71 | myled = 1; |
jstephens78 | 0:da114b98e013 | 72 | wait(0.2); |
jstephens78 | 0:da114b98e013 | 73 | myled = 0; |
jstephens78 | 0:da114b98e013 | 74 | wait(0.2); |
jstephens78 | 0:da114b98e013 | 75 | } |
jstephens78 | 0:da114b98e013 | 76 | } |