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