version one

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed wave_player

Committer:
Septimus
Date:
Mon Mar 24 17:45:38 2014 +0000
Revision:
0:82705a2c05d1
Child:
1:f35df38e9b16
version one

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 0:82705a2c05d1 32 pc.printf("%8.2fV %8.2f in\n", volts, inches);
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 0:82705a2c05d1 37 if(inches < 8){
Septimus 0:82705a2c05d1 38
Septimus 0:82705a2c05d1 39 if(trigger != 0){
Septimus 0:82705a2c05d1 40 LCD.cls();
Septimus 0:82705a2c05d1 41 }
Septimus 0:82705a2c05d1 42
Septimus 0:82705a2c05d1 43 LCD.media_init();
Septimus 0:82705a2c05d1 44 LCD.set_sector_address(0x000F, 0x2301);
Septimus 0:82705a2c05d1 45 LCD.display_image(0,0);
Septimus 0:82705a2c05d1 46 wave_file=fopen("/sd/AngryCat.wav","r");
Septimus 0:82705a2c05d1 47 waver.play(wave_file);
Septimus 0:82705a2c05d1 48 fclose(wave_file);
Septimus 0:82705a2c05d1 49 trigger=0;
Septimus 0:82705a2c05d1 50 }
Septimus 0:82705a2c05d1 51
Septimus 0:82705a2c05d1 52
Septimus 0:82705a2c05d1 53 else if(inches >= 8 && inches < 12){
Septimus 0:82705a2c05d1 54
Septimus 0:82705a2c05d1 55 if(trigger != 1){
Septimus 0:82705a2c05d1 56 LCD.cls();
Septimus 0:82705a2c05d1 57 }
Septimus 0:82705a2c05d1 58
Septimus 0:82705a2c05d1 59 LCD.media_init();
Septimus 0:82705a2c05d1 60 LCD.set_sector_address(0x000F, 0x2342);
Septimus 0:82705a2c05d1 61 LCD.display_image(0,0);
Septimus 0:82705a2c05d1 62 wave_file=fopen("/sd/NervousCat.wav","r");
Septimus 0:82705a2c05d1 63 waver.play(wave_file);
Septimus 0:82705a2c05d1 64 fclose(wave_file);
Septimus 0:82705a2c05d1 65 trigger=1;
Septimus 0:82705a2c05d1 66 }
Septimus 0:82705a2c05d1 67
Septimus 0:82705a2c05d1 68 else if(inches > 12){
Septimus 0:82705a2c05d1 69
Septimus 0:82705a2c05d1 70 if(trigger != 2){
Septimus 0:82705a2c05d1 71 LCD.cls();
Septimus 0:82705a2c05d1 72 }
Septimus 0:82705a2c05d1 73
Septimus 0:82705a2c05d1 74 LCD.media_init();
Septimus 0:82705a2c05d1 75 LCD.set_sector_address(0x000F, 0x2383);
Septimus 0:82705a2c05d1 76 LCD.display_image(0,0);
Septimus 0:82705a2c05d1 77 wave_file=fopen("/sd/NiceCat.wav","r");
Septimus 0:82705a2c05d1 78 waver.play(wave_file);
Septimus 0:82705a2c05d1 79 fclose(wave_file);
Septimus 0:82705a2c05d1 80 trigger=2;
Septimus 0:82705a2c05d1 81 }
Septimus 0:82705a2c05d1 82 }
Septimus 0:82705a2c05d1 83 }