A program designed to get the distance from an SRF02 distance sensor and create an audible and visual indication of that distance with data logging capabilities.
Dependencies: N5110 PowerControl SRF02 mbed
Diff: main.cpp
- Revision:
- 5:c57cd4c57c40
- Parent:
- 4:0bd5c189f2f3
- Child:
- 6:d6afc4026a1d
--- a/main.cpp Thu Apr 09 09:49:06 2015 +0000 +++ b/main.cpp Thu Apr 09 10:18:28 2015 +0000 @@ -1,7 +1,7 @@ // Distance Sensor Project // Main File "main.cpp" // Designed By Sam Russell (200773195) -// Date: 07/04/2015 || Version: 0.4a +// Date: 09/04/2015 || Version: 0.4b #include "main.h" @@ -150,11 +150,8 @@ void buttonPressed() { + wait(0.2); mode++; //count up mode when button is pressed. - if(mode>2) { - //when mode becomes an integer value of 3, reset mode. - mode=0; - } } int main() @@ -164,7 +161,7 @@ timer.attach(&timerExpired,1); display.init(); // Initialise the display. display.clear(); // Clears the starting pattern from the screen. - welcomeScreen(); + welcomeScreen(); // Displays the welcome screen. pc.attach(&serialISR); // attach serial ISR char buffer[30]; // buffer used to store time string set_time(0); // initialise time to 1st January 1970 @@ -191,6 +188,9 @@ } else if(mode==2) { display.printString("Power Saving",8,5); //Print mode name to screen. leds = 0; //mbed LED indication of mode. + } else if(mode==3) { + //when mode becomes an integer value of 3, reset mode. + mode=0; } char buffer2[50]; // buffer2 is used to store the distance string. sprintf (buffer2, "%d cm", distance); //Composes a printf compatable string and stores the distance in the buffer2.