This program senses the status of a tilt switch using the MBED LPC1768

Dependencies:   mbed

Committer:
rmcwilliam101
Date:
Mon Jun 29 12:26:37 2015 +0000
Revision:
0:bce3540c3f6f
This program senses the status of a tilt switch circuit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rmcwilliam101 0:bce3540c3f6f 1 #include "mbed.h"
rmcwilliam101 0:bce3540c3f6f 2 /* This program generates a tilt alarm using LED1 */
rmcwilliam101 0:bce3540c3f6f 3
rmcwilliam101 0:bce3540c3f6f 4 /* Define some useful constants */
rmcwilliam101 0:bce3540c3f6f 5 #define ON 1
rmcwilliam101 0:bce3540c3f6f 6 #define OFF 0
rmcwilliam101 0:bce3540c3f6f 7 #define HIGH 1
rmcwilliam101 0:bce3540c3f6f 8 #define LOW 0
rmcwilliam101 0:bce3540c3f6f 9
rmcwilliam101 0:bce3540c3f6f 10 /* Use LED1 */
rmcwilliam101 0:bce3540c3f6f 11 DigitalOut light1(LED1);
rmcwilliam101 0:bce3540c3f6f 12 /* Use pin 5 for the tilt sensor */
rmcwilliam101 0:bce3540c3f6f 13 DigitalIn tilt_sens(p5);
rmcwilliam101 0:bce3540c3f6f 14
rmcwilliam101 0:bce3540c3f6f 15 /* Main loop */
rmcwilliam101 0:bce3540c3f6f 16 int main()
rmcwilliam101 0:bce3540c3f6f 17 {
rmcwilliam101 0:bce3540c3f6f 18 while(1)
rmcwilliam101 0:bce3540c3f6f 19 {
rmcwilliam101 0:bce3540c3f6f 20 /* Set LED1 depending upon the current status of the tilt sensor */
rmcwilliam101 0:bce3540c3f6f 21 if (tilt_sens == HIGH)
rmcwilliam101 0:bce3540c3f6f 22 {
rmcwilliam101 0:bce3540c3f6f 23 light1=ON; /* Tilt alarm LED is ON */
rmcwilliam101 0:bce3540c3f6f 24 }
rmcwilliam101 0:bce3540c3f6f 25 if (tilt_sens == LOW)
rmcwilliam101 0:bce3540c3f6f 26 {
rmcwilliam101 0:bce3540c3f6f 27 light1=OFF; /* Tilt alarm LED is OFF */
rmcwilliam101 0:bce3540c3f6f 28 }
rmcwilliam101 0:bce3540c3f6f 29 wait(0.3); /* Wait 0.3 seconds */
rmcwilliam101 0:bce3540c3f6f 30 }
rmcwilliam101 0:bce3540c3f6f 31 }
rmcwilliam101 0:bce3540c3f6f 32