
Tapton school eds robot project mbed2
Dependencies: SDFileSystem SRF05 mbed wave_player_appbd
Revision 0:5482b23752a8, committed 2017-03-14
- Comitter:
- matt8174
- Date:
- Tue Mar 14 13:46:35 2017 +0000
- Child:
- 1:fdf0c4de9039
- Commit message:
- Mbed2 Tapton school eds robot project
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Tue Mar 14 13:46:35 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/SDFileSystem/#b1266513e24b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SRF05.lib Tue Mar 14 13:46:35 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/simon/code/SRF05/#e758665e072c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Mar 14 13:46:35 2017 +0000 @@ -0,0 +1,486 @@ +// Mbed 2 Additional sensors and Audio control + +#include "mbed.h" +#include "SRF05.h" +#include "SDFileSystem.h" +#include "wave_player.h" +#include "string" +#include <stdio.h> +#include <stdlib.h> +#include <iostream> +//Serial pc(USBTX, USBRX); // for terminal diagnostics + +Serial communicate(p28, p27);// serial comms to mbed 1 tx and rx +SRF05 srf(p9, p10);// serial comms to distance sensor tx, rx +SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card +AnalogOut DACout(p18); //to audio amplifier and speaker +PwmOut PWMout(p26); +wave_player waver(&DACout,&PWMout); +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); +DigitalOut stopgo (p20); // sends signal to mbed1 to move forward or not + +char receivedchar[10]; //array used for received characters from mbed1 +int command_num; +int distcheck; +int b; + +void rxCallback() //interrupt from rx serial port +{ + myled3=!myled3; + receivedchar[0]=communicate.getc(); // put received character from mbed2 into array for later + command_num=receivedchar[0]; + // pc.printf("%d ",receivedchar[0]); + +} + +void txCallback() //interrupt from rx serial port +{ + myled4=!myled4; + // pc.printf("%d ",receivedchar[0]); +} + + +int main () +{ + bool nerror = true; + + communicate.baud(19200); //to mbed 1 + // pc.baud(19200); //for diagnostics + setbuf(stdin,NULL); //clear serial input buffer + //for serial interrupt callback function + communicate.attach(&txCallback, Serial::TxIrq); + communicate.attach(&rxCallback, Serial::RxIrq); + FILE *wave_file; + command_num=0; + receivedchar[0]=0; + distcheck=0; + stopgo=0; + char buffer [20]; + buffer[0]=0; + myled1=0; + + //enter infinite loop +wait(1); + while(nerror) + { + + distcheck = srf.read(); + // pc.printf(" %d",distcheck); + if (distcheck<=15) //too close + { + myled1=stopgo; + stopgo=1; // not ok to move forward, raise p20 + // pc.printf("%d NOT OK\n", distcheck); + } + else { + stopgo=0; + myled1=stopgo; + } + // pc.printf(" %d",distcheck); + + // if (command_num!=0) + // { + if(command_num >= 49 && command_num <= 53) // 1 to 5 (MOVEMENT) + { + switch(command_num) + { + case '1': + // sprintf(buffer, "/sd/voice%d.wav", command_num); + sprintf(buffer, "/sd/voice42.wav"); //Forward + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case '2': + // sprintf(buffer, "/sd/voice%d.wav", command_num); + sprintf(buffer, "/sd/voice43.wav"); //Right + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case '3': + // sprintf(buffer, "/sd/voice%d.wav", command_num); + sprintf(buffer, "/sd/voice44.wav"); //Reverse + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case '4': + // sprintf(buffer, "/sd/voice%d.wav", command_num); + sprintf(buffer, "/sd/voice45.wav"); //Left + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case '5': // cant move forward + // sprintf(buffer, "/sd/voice%d.wav", command_num); + sprintf(buffer, "/sd/voice46.wav"); // Blocked + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + } + } + if(command_num >= 97 && command_num <= 106) // a to j (NUMBERS) + { + switch(command_num) + { + + case 'a': + sprintf(buffer,"/sd/voice41.wav"); // 0 + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'b': + sprintf(buffer,"/sd/voice31.wav"); // 1 + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'c': + sprintf(buffer,"/sd/voice32.wav"); // 2 + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'd': + sprintf(buffer,"/sd/voice33.wav"); // 3 + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'e': + sprintf(buffer,"/sd/voice34.wav"); // 4 + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'f': + sprintf(buffer,"/sd/voice35.wav"); // 5 + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'g': + sprintf(buffer,"/sd/voice36.wav"); // 6 + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'h': + sprintf(buffer,"/sd/voice37.wav"); // 7 + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'i': + sprintf(buffer,"/sd/voice38.wav"); // 8 + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'j': + sprintf(buffer,"/sd/voice39.wav"); // 9 + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + } + } + + + if(command_num >= 65 && command_num <= 90) // A to Z (LETTERS) + { + switch(command_num) + { + case 'A': + sprintf(buffer,"/sd/voice5.wav"); // A + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'B': + sprintf(buffer,"/sd/voice6.wav"); // B + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'C': + sprintf(buffer,"/sd/voice7.wav"); // C + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'D': + sprintf(buffer,"/sd/voice8.wav"); // D + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'E': + sprintf(buffer,"/sd/voice9.wav"); // E + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'F': + sprintf(buffer,"/sd/voice10.wav"); // F + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'G': + sprintf(buffer,"/sd/voice11.wav"); // G + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'H': + sprintf(buffer,"/sd/voice12.wav"); // H + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'I': + sprintf(buffer,"/sd/voice13.wav"); // I + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'J': + sprintf(buffer,"/sd/voice14.wav"); // J + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'K': + sprintf(buffer,"/sd/voice15.wav"); // K + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'L': + sprintf(buffer,"/sd/voice16.wav"); // L + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'M': + sprintf(buffer,"/sd/voice17.wav"); // M + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'N': + sprintf(buffer,"/sd/voice18.wav"); // N + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'O': + sprintf(buffer,"/sd/voice19.wav"); // O + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'P': + sprintf(buffer,"/sd/voice20.wav"); // P + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + + case 'Q': + sprintf(buffer,"/sd/voice21.wav"); // Q + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'R': + sprintf(buffer,"/sd/voice22.wav"); // R + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'S': + sprintf(buffer,"/sd/voice23.wav"); // S + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'T': + sprintf(buffer,"/sd/voice24.wav"); // T + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'U': + sprintf(buffer,"/sd/voice25.wav"); // U + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'V': + sprintf(buffer,"/sd/voice26.wav"); // V + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'W': + sprintf(buffer,"/sd/voice27.wav"); // W + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'X': + sprintf(buffer,"/sd/voice28.wav"); // X + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'Y': + sprintf(buffer,"/sd/voice29.wav"); // Y + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + case 'Z': + sprintf(buffer,"/sd/voice30.wav"); // Z + wave_file=fopen(buffer ,"r"); + waver.play(wave_file); + fclose(wave_file); + wait(0.1); + command_num=0; + break; + + + } //switch + } // + // } // lower if command num + } //while +}//main + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Mar 14 13:46:35 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/176b8275d35d \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player_appbd.lib Tue Mar 14 13:46:35 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/mptapton/code/wave_player_appbd/#c056757cda3a