SharpShooter
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
main.cpp@5:f51cdddf541e, 2016-10-28 (annotated)
- Committer:
- jboettcher
- Date:
- Fri Oct 28 00:36:11 2016 +0000
- Revision:
- 5:f51cdddf541e
- Parent:
- 1:8a3fa9e90572
starting shooter class;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jboettcher | 0:137546fb5da1 | 1 | #include "mbed.h" |
jboettcher | 0:137546fb5da1 | 2 | #include "Speaker.h" |
jboettcher | 0:137546fb5da1 | 3 | #include "uLCD_4DGL.h" |
jboettcher | 0:137546fb5da1 | 4 | #include "SDFileSystem.h" |
jboettcher | 0:137546fb5da1 | 5 | #include "wave_player.h" |
jboettcher | 1:8a3fa9e90572 | 6 | #include "Nav_Switch.h" |
jboettcher | 1:8a3fa9e90572 | 7 | #include "rtos.h" |
jboettcher | 0:137546fb5da1 | 8 | |
jboettcher | 0:137546fb5da1 | 9 | DigitalOut myled(LED1); |
jboettcher | 0:137546fb5da1 | 10 | |
jboettcher | 0:137546fb5da1 | 11 | /*uLCD instantiation*/ |
jboettcher | 0:137546fb5da1 | 12 | uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; |
jboettcher | 0:137546fb5da1 | 13 | |
jboettcher | 1:8a3fa9e90572 | 14 | Nav_Switch myNav( p24, p25, p26, p27, p28); //up, down, left, right, fire |
jboettcher | 1:8a3fa9e90572 | 15 | |
jboettcher | 0:137546fb5da1 | 16 | Mutex mutex; |
jboettcher | 0:137546fb5da1 | 17 | |
jboettcher | 0:137546fb5da1 | 18 | /* wave player instantiation*/ |
jboettcher | 0:137546fb5da1 | 19 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card |
jboettcher | 0:137546fb5da1 | 20 | AnalogOut DACout(p18); |
jboettcher | 0:137546fb5da1 | 21 | wave_player waver(&DACout); |
jboettcher | 0:137546fb5da1 | 22 | |
jboettcher | 0:137546fb5da1 | 23 | /*play wav file on sd and when playing led1 turns on*/ |
jboettcher | 0:137546fb5da1 | 24 | void wav_thread3(void const *args) { |
jboettcher | 0:137546fb5da1 | 25 | while (1) { |
jboettcher | 0:137546fb5da1 | 26 | FILE *wave_file; |
jboettcher | 0:137546fb5da1 | 27 | wave_file=fopen("/sd/wavfiles/alarm.wav","r"); |
jboettcher | 0:137546fb5da1 | 28 | waver.play(wave_file); |
jboettcher | 0:137546fb5da1 | 29 | fclose(wave_file); |
jboettcher | 0:137546fb5da1 | 30 | } |
jboettcher | 0:137546fb5da1 | 31 | } |
jboettcher | 0:137546fb5da1 | 32 | |
jboettcher | 1:8a3fa9e90572 | 33 | void switch_thread5(void const *args) { |
jboettcher | 0:137546fb5da1 | 34 | while (true) { |
jboettcher | 1:8a3fa9e90572 | 35 | if(myNav.fire()) myled=!myled; |
jboettcher | 1:8a3fa9e90572 | 36 | if(myNav.up()) myled=!myled; |
jboettcher | 1:8a3fa9e90572 | 37 | if(myNav.down()) myled=!myled; |
jboettcher | 1:8a3fa9e90572 | 38 | if(myNav.right()) myled=!myled; |
jboettcher | 1:8a3fa9e90572 | 39 | if(myNav.left()) myled=!myled; |
jboettcher | 1:8a3fa9e90572 | 40 | //Thread::wait(500); |
jboettcher | 0:137546fb5da1 | 41 | } |
jboettcher | 0:137546fb5da1 | 42 | } |
jboettcher | 1:8a3fa9e90572 | 43 | |
jboettcher | 0:137546fb5da1 | 44 | int main() { |
jboettcher | 1:8a3fa9e90572 | 45 | myled=0; |
jboettcher | 1:8a3fa9e90572 | 46 | //Thread thread2(switch_thread5); |
jboettcher | 1:8a3fa9e90572 | 47 | //Thread thread3(wav_thread3); |
jboettcher | 1:8a3fa9e90572 | 48 | while(1) { |
jboettcher | 5:f51cdddf541e | 49 | uLCD.rectangle(0,0,128,10,0xFFFFFF); |
jboettcher | 1:8a3fa9e90572 | 50 | } |
jboettcher | 0:137546fb5da1 | 51 | } |