It begins
Dependencies: SDFileSystem mbed-rtos mbed wave_player
Fork of BAT_senior_design by
Diff: main.cpp
- Revision:
- 4:cc181f8f2bd1
- Parent:
- 3:9ed43e974156
- Child:
- 6:1aa86ad19af9
diff -r 9ed43e974156 -r cc181f8f2bd1 main.cpp --- a/main.cpp Fri Oct 06 13:43:36 2017 +0000 +++ b/main.cpp Wed Oct 11 14:51:39 2017 +0000 @@ -1,51 +1,77 @@ #include "mbed.h" -#include "Servo.h" - -// Azra +#include "wave_player.h" +#include "SDFileSystem.h" PwmOut myservo(p21); DigitalIn pb1 (p20); //AnalogIn linpot(p20); Serial pc(USBTX, USBRX); -DigitalOut myled(LED1); +//DigitalOut myled(LED1); +SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card +AnalogOut DACout(p26); +wave_player waver(&DACout); + +void moveServoIn() +{ + while(pb1 == 1) + //myled = 1; + // rotate 90 degrees one way + for(int i=3; i<=7; i++) { + myservo = i/100.0; + wait(0.01); + } +} + +void moveServoOut() +{ + while(pb1 == 1) + //myled = 0; + for(int i=7; i>3; i--) { + myservo = i/100.0; + wait(0.01); + } +} + +void playSound() +{ + FILE *wave_file; + wave_file=fopen("/sd/police_siren.wav","r"); + waver.play(wave_file); + fclose(wave_file); +} int main() { + pc.printf("begin\n"); + // button up: state = 0, button halfway: state = 1; button down: state = 2 - //int state = 0; - pc.printf("begin\n"); int state = 2; + + // pull up the pushbutton to prevent bouncing pb1.mode(PullUp); wait(.001); + + // servo begins at 30 degrees for(int i=0; i<=3; i++) { myservo = i/100.0; wait(0.01); } + while(1) { // Servo code if (pb1 == 1 && state == 2) { - while(pb1 == 1) - myled = 1; - // rotate 90 degrees one way - for(int i=3; i<=7; i++) { - myservo = i/100.0; - wait(0.01); - } + moveServoIn(); state = 1; } - //wait(1.0); // rotate 90 degrees other way if (pb1 == 1 && state == 1) { - while(pb1 == 1) - myled = 0; - for(int i=7; i>3; i--) { - myservo = i/100.0; - wait(0.01); - } - //wait(0.1); + moveServoOut(); state = 2; } - //wait(1.0); + + // SD card code + + // speaker code // read linear potentiometer //if (linpot < 0.5) {