version one

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed wave_player

Committer:
Septimus
Date:
Tue Mar 25 03:08:09 2014 +0000
Revision:
1:f35df38e9b16
Parent:
0:82705a2c05d1
Final Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Septimus 0:82705a2c05d1 1 #include "mbed.h"
Septimus 0:82705a2c05d1 2 #include "uLCD_4DGL.h"
Septimus 0:82705a2c05d1 3 #include "SDFileSystem.h"
Septimus 0:82705a2c05d1 4 #include "wave_player.h"
Septimus 0:82705a2c05d1 5
Septimus 0:82705a2c05d1 6 //The section below lists all inputs and outputs for the program.
Septimus 0:82705a2c05d1 7 //pc allows us to read data on the PC should we need to check that correct values are going through.
Septimus 0:82705a2c05d1 8 //LCD allows us to connect to the uLCD display and send commands as needed.
Septimus 0:82705a2c05d1 9 //sd allows us to send commands to the SD card reader on the board.
Septimus 0:82705a2c05d1 10 //DACout is connected to the speaker and outputs audio gathered from the SD Card reader.
Septimus 0:82705a2c05d1 11 //Sonr allows for the MBED to read in data from the EZ-LV Sonar.
Septimus 0:82705a2c05d1 12 //waver allows us to connect to DACout and play audio files as needed.
Septimus 0:82705a2c05d1 13
Septimus 0:82705a2c05d1 14 Serial pc(USBTX,USBRX);
Septimus 0:82705a2c05d1 15 uLCD_4DGL LCD(p9,p10,p11);
Septimus 0:82705a2c05d1 16 SDFileSystem sd(p5, p6, p7, p12, "sd"); //SD card
Septimus 0:82705a2c05d1 17 AnalogOut DACout(p18);
Septimus 0:82705a2c05d1 18 AnalogIn Sonr(p17);
Septimus 0:82705a2c05d1 19 wave_player waver(&DACout);
Septimus 0:82705a2c05d1 20
Septimus 0:82705a2c05d1 21 FILE *wave_file;
Septimus 0:82705a2c05d1 22 int trigger=4;
Septimus 0:82705a2c05d1 23 int Cat=0;
Septimus 0:82705a2c05d1 24 float adc, volts, inches;
Septimus 0:82705a2c05d1 25 int feet, in;
Septimus 0:82705a2c05d1 26
Septimus 0:82705a2c05d1 27
Septimus 0:82705a2c05d1 28 int main() {
Septimus 0:82705a2c05d1 29
Septimus 0:82705a2c05d1 30 while(1){
Septimus 0:82705a2c05d1 31
Septimus 1:f35df38e9b16 32 pc.printf("%8.2fV %8.2f in\n", volts, inches); //If the Sonar needs to be checked for functionality
Septimus 0:82705a2c05d1 33 adc = Sonr.read(); // read analog as a float
Septimus 0:82705a2c05d1 34 volts = adc * 3.3; // convert to volts
Septimus 0:82705a2c05d1 35 inches = volts / 0.0064; // 3.3V supply: 6.4mV per inch
Septimus 0:82705a2c05d1 36
Septimus 1:f35df38e9b16 37
Septimus 1:f35df38e9b16 38 //The first condition is that if the Sonar detects an object less than 8 inches above, then the AngryCat.wav file will play
Septimus 1:f35df38e9b16 39 //through the speaker and the LCD display will access from its SD card the AngryCat.jpg file.
Septimus 1:f35df38e9b16 40
Septimus 1:f35df38e9b16 41
Septimus 0:82705a2c05d1 42 if(inches < 8){
Septimus 0:82705a2c05d1 43
Septimus 1:f35df38e9b16 44 //The below if statement runs only if the entire preceding if statement has run at least once. It ensures that when
Septimus 1:f35df38e9b16 45 //the program runs, it only clears the screen when an image transition occurs.
Septimus 1:f35df38e9b16 46
Septimus 0:82705a2c05d1 47 if(trigger != 0){
Septimus 0:82705a2c05d1 48 LCD.cls();
Septimus 0:82705a2c05d1 49 }
Septimus 0:82705a2c05d1 50
Septimus 0:82705a2c05d1 51 LCD.media_init();
Septimus 0:82705a2c05d1 52 LCD.set_sector_address(0x000F, 0x2301);
Septimus 0:82705a2c05d1 53 LCD.display_image(0,0);
Septimus 0:82705a2c05d1 54 wave_file=fopen("/sd/AngryCat.wav","r");
Septimus 0:82705a2c05d1 55 waver.play(wave_file);
Septimus 0:82705a2c05d1 56 fclose(wave_file);
Septimus 0:82705a2c05d1 57 trigger=0;
Septimus 0:82705a2c05d1 58 }
Septimus 0:82705a2c05d1 59
Septimus 1:f35df38e9b16 60 //The second condition is that if the Sonar detects an object between 8 inches to 12 inches above the Sonar, then the NervousCat.wav file will play
Septimus 1:f35df38e9b16 61 //through the speaker and the LCD will display from its SD card the NervousCat.jpg file.
Septimus 1:f35df38e9b16 62
Septimus 0:82705a2c05d1 63
Septimus 0:82705a2c05d1 64 else if(inches >= 8 && inches < 12){
Septimus 0:82705a2c05d1 65
Septimus 0:82705a2c05d1 66 if(trigger != 1){
Septimus 0:82705a2c05d1 67 LCD.cls();
Septimus 0:82705a2c05d1 68 }
Septimus 0:82705a2c05d1 69
Septimus 0:82705a2c05d1 70 LCD.media_init();
Septimus 0:82705a2c05d1 71 LCD.set_sector_address(0x000F, 0x2342);
Septimus 0:82705a2c05d1 72 LCD.display_image(0,0);
Septimus 0:82705a2c05d1 73 wave_file=fopen("/sd/NervousCat.wav","r");
Septimus 0:82705a2c05d1 74 waver.play(wave_file);
Septimus 0:82705a2c05d1 75 fclose(wave_file);
Septimus 0:82705a2c05d1 76 trigger=1;
Septimus 0:82705a2c05d1 77 }
Septimus 0:82705a2c05d1 78
Septimus 1:f35df38e9b16 79
Septimus 1:f35df38e9b16 80 //The last condition is that if the Sonar detects an object further than 12 inches above the Sonar, then the NiceCat.wav file will play
Septimus 1:f35df38e9b16 81 //through the speaker and the LCD will display from its SD card the NiceCat.jpg file.
Septimus 1:f35df38e9b16 82
Septimus 1:f35df38e9b16 83
Septimus 0:82705a2c05d1 84 else if(inches > 12){
Septimus 0:82705a2c05d1 85
Septimus 0:82705a2c05d1 86 if(trigger != 2){
Septimus 0:82705a2c05d1 87 LCD.cls();
Septimus 0:82705a2c05d1 88 }
Septimus 0:82705a2c05d1 89
Septimus 0:82705a2c05d1 90 LCD.media_init();
Septimus 0:82705a2c05d1 91 LCD.set_sector_address(0x000F, 0x2383);
Septimus 0:82705a2c05d1 92 LCD.display_image(0,0);
Septimus 0:82705a2c05d1 93 wave_file=fopen("/sd/NiceCat.wav","r");
Septimus 0:82705a2c05d1 94 waver.play(wave_file);
Septimus 0:82705a2c05d1 95 fclose(wave_file);
Septimus 0:82705a2c05d1 96 trigger=2;
Septimus 0:82705a2c05d1 97 }
Septimus 0:82705a2c05d1 98 }
Septimus 0:82705a2c05d1 99 }