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