For Nikhil
Dependencies: 4DGL-uLCD-SE EthernetInterface Game_Synchronizer MMA8452 SDFileSystem mbed-rtos mbed wave_player
Fork of 2035_Tanks_Shell by
misc/misc.cpp@22:3c68eea5a609, 2015-10-29 (annotated)
- Committer:
- jford38
- Date:
- Thu Oct 29 05:14:49 2015 +0000
- Revision:
- 22:3c68eea5a609
- Parent:
- 20:6a58052b0140
- Child:
- 23:77049670cae6
The Shell for students to fill in to play their tanks game.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jford38 | 20:6a58052b0140 | 1 | #include "misc.h" |
jford38 | 22:3c68eea5a609 | 2 | #include "uLCD_4DGL.h" |
jford38 | 22:3c68eea5a609 | 3 | #include "SDFileSystem.h" |
jford38 | 22:3c68eea5a609 | 4 | #include "wave_player.h" |
jford38 | 22:3c68eea5a609 | 5 | |
jford38 | 22:3c68eea5a609 | 6 | extern uLCD_4DGL uLCD; |
jford38 | 22:3c68eea5a609 | 7 | extern wave_player player; |
jford38 | 22:3c68eea5a609 | 8 | |
jford38 | 14:36c306e26317 | 9 | |
jford38 | 14:36c306e26317 | 10 | int CONVERT_24_TO_16_BPP(int col_24) { |
jford38 | 14:36c306e26317 | 11 | int b = col_24 & 0xFF; |
jford38 | 14:36c306e26317 | 12 | int g = (col_24 >> 8) & 0xFF; |
jford38 | 14:36c306e26317 | 13 | int r = (col_24 >> 16)& 0xFF; |
jford38 | 14:36c306e26317 | 14 | |
jford38 | 14:36c306e26317 | 15 | r >>= 3; |
jford38 | 14:36c306e26317 | 16 | g >>= 2; |
jford38 | 14:36c306e26317 | 17 | b >>= 3; |
jford38 | 14:36c306e26317 | 18 | |
jford38 | 14:36c306e26317 | 19 | return r<<11 | g<<5 | b; |
jford38 | 22:3c68eea5a609 | 20 | } |
jford38 | 22:3c68eea5a609 | 21 | |
jford38 | 22:3c68eea5a609 | 22 | // Given the filename of a .wav file in the SD card, play the file over the speaker. |
jford38 | 22:3c68eea5a609 | 23 | void playSound(char * wav) |
jford38 | 22:3c68eea5a609 | 24 | { |
jford38 | 22:3c68eea5a609 | 25 | // open wav file |
jford38 | 22:3c68eea5a609 | 26 | FILE *wave_file; |
jford38 | 22:3c68eea5a609 | 27 | wave_file=fopen(wav,"r"); |
jford38 | 22:3c68eea5a609 | 28 | |
jford38 | 22:3c68eea5a609 | 29 | if(wave_file == NULL){ |
jford38 | 22:3c68eea5a609 | 30 | uLCD.locate(0,4); |
jford38 | 22:3c68eea5a609 | 31 | uLCD.printf("Error in SD"); |
jford38 | 22:3c68eea5a609 | 32 | return; |
jford38 | 22:3c68eea5a609 | 33 | } |
jford38 | 22:3c68eea5a609 | 34 | // play wav file |
jford38 | 22:3c68eea5a609 | 35 | player.play(wave_file); |
jford38 | 22:3c68eea5a609 | 36 | |
jford38 | 22:3c68eea5a609 | 37 | // close wav file |
jford38 | 22:3c68eea5a609 | 38 | fclose(wave_file); |
jford38 | 14:36c306e26317 | 39 | } |