Dependencies: mbed wave_player
main.cpp@0:cbaaf2c707d2, 2016-03-14 (annotated)
- Committer:
- Alexw2011
- Date:
- Mon Mar 14 04:12:35 2016 +0000
- Revision:
- 0:cbaaf2c707d2
Demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Alexw2011 | 0:cbaaf2c707d2 | 1 | #include "mbed.h" |
Alexw2011 | 0:cbaaf2c707d2 | 2 | #include "Speaker.h" |
Alexw2011 | 0:cbaaf2c707d2 | 3 | |
Alexw2011 | 0:cbaaf2c707d2 | 4 | AnalogIn magsense(p16); |
Alexw2011 | 0:cbaaf2c707d2 | 5 | |
Alexw2011 | 0:cbaaf2c707d2 | 6 | DigitalOut myled1(LED1); |
Alexw2011 | 0:cbaaf2c707d2 | 7 | DigitalOut myled2(LED2); |
Alexw2011 | 0:cbaaf2c707d2 | 8 | DigitalOut myled3(LED3); |
Alexw2011 | 0:cbaaf2c707d2 | 9 | DigitalOut myled4(LED4); |
Alexw2011 | 0:cbaaf2c707d2 | 10 | |
Alexw2011 | 0:cbaaf2c707d2 | 11 | Serial pc(USBTX,USBRX); // Optional, this is just to provide feedback. |
Alexw2011 | 0:cbaaf2c707d2 | 12 | Speaker mySpeaker(p21); // Create a Speaker object |
Alexw2011 | 0:cbaaf2c707d2 | 13 | |
Alexw2011 | 0:cbaaf2c707d2 | 14 | int sensor = 0; |
Alexw2011 | 0:cbaaf2c707d2 | 15 | |
Alexw2011 | 0:cbaaf2c707d2 | 16 | |
Alexw2011 | 0:cbaaf2c707d2 | 17 | int main() { |
Alexw2011 | 0:cbaaf2c707d2 | 18 | |
Alexw2011 | 0:cbaaf2c707d2 | 19 | while(1) { |
Alexw2011 | 0:cbaaf2c707d2 | 20 | |
Alexw2011 | 0:cbaaf2c707d2 | 21 | sensor=magsense.read(); // Read in the sensor value |
Alexw2011 | 0:cbaaf2c707d2 | 22 | |
Alexw2011 | 0:cbaaf2c707d2 | 23 | if(sensor!=0){ //If the contact is broken, turn on the LED's and sound the alarm! |
Alexw2011 | 0:cbaaf2c707d2 | 24 | |
Alexw2011 | 0:cbaaf2c707d2 | 25 | myled1=1; |
Alexw2011 | 0:cbaaf2c707d2 | 26 | myled2=1; |
Alexw2011 | 0:cbaaf2c707d2 | 27 | myled3=1; |
Alexw2011 | 0:cbaaf2c707d2 | 28 | myled4=1; |
Alexw2011 | 0:cbaaf2c707d2 | 29 | |
Alexw2011 | 0:cbaaf2c707d2 | 30 | mySpeaker.PlayNote(1200, 0.1, 1.0); |
Alexw2011 | 0:cbaaf2c707d2 | 31 | mySpeaker.PlayNote(1205, 0.1, 1.0); |
Alexw2011 | 0:cbaaf2c707d2 | 32 | mySpeaker.PlayNote(1210, 0.1, 1.0); |
Alexw2011 | 0:cbaaf2c707d2 | 33 | |
Alexw2011 | 0:cbaaf2c707d2 | 34 | pc.printf("Value %d,", sensor); |
Alexw2011 | 0:cbaaf2c707d2 | 35 | } |
Alexw2011 | 0:cbaaf2c707d2 | 36 | |
Alexw2011 | 0:cbaaf2c707d2 | 37 | else { |
Alexw2011 | 0:cbaaf2c707d2 | 38 | |
Alexw2011 | 0:cbaaf2c707d2 | 39 | myled1=0; |
Alexw2011 | 0:cbaaf2c707d2 | 40 | myled2=0; |
Alexw2011 | 0:cbaaf2c707d2 | 41 | myled3=0; |
Alexw2011 | 0:cbaaf2c707d2 | 42 | myled4=0; |
Alexw2011 | 0:cbaaf2c707d2 | 43 | } |
Alexw2011 | 0:cbaaf2c707d2 | 44 | |
Alexw2011 | 0:cbaaf2c707d2 | 45 | } |
Alexw2011 | 0:cbaaf2c707d2 | 46 | } |