Richard McWilliam
/
Pot
This program senses the analogue voltage of a potentiometer using the MBED LPC1768
Revision 0:7186208c7c28, committed 2015-06-29
- Comitter:
- rmcwilliam101
- Date:
- Mon Jun 29 12:26:07 2015 +0000
- Commit message:
- This program senses the status of a tilt switch circuit
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jun 29 12:26:07 2015 +0000 @@ -0,0 +1,36 @@ +#include "mbed.h" +/* This program reads output from built-in analogue to digital converter (ADC) */ + +/* Define some useful constants */ +#define ON 1 +#define OFF 0 + +/* Create objects for input/output */ +AnalogIn pot_reading(p15); /* ADC input is connected to Pin 15 */ + +/* Create names for lights */ +DigitalOut light1(LED1); /* Control LED1 using light1 */ +DigitalOut light2(LED2); /* Control LED2 using light2 */ +DigitalOut light3(LED3); /* Control LED3 using light3 */ +DigitalOut light4(LED4); /* Control LED4 using light4 */ + +/* Main loop */ +int main() +{ + float reading; /* A variable is needed to store ADC reading */ + + /* Define a while loop that runs forever (or until the MBED is reset) */ + while(1) + { + reading=pot_reading; /* store reading from the ADC into variable 'reading' */ + if(reading > 0.5) /* Checks whether value stored in 'reading' is greater than 0.5 */ + { + light1=ON; /* light1 is turned on when ADC reading exceeds 0.5 */ + } + else + { + light1=OFF; /* light1 is turned off when ADC reading is less than 0.5 */ + } + wait(0.1); /* Pause for 0.1 seconds before taking another reading */ + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Jun 29 12:26:07 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7 \ No newline at end of file