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

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 /* This program generates a tilt alarm using LED1 */
00003 
00004 /* Define some useful constants */
00005 #define ON 1
00006 #define OFF 0
00007 #define HIGH 1
00008 #define LOW 0
00009 
00010 /* Use LED1 */
00011 DigitalOut light1(LED1);
00012 /* Use pin 5 for the tilt sensor */
00013 DigitalIn tilt_sens(p5); 
00014 
00015 /* Main loop */
00016 int main() 
00017 {
00018     while(1) 
00019     {
00020         /* Set LED1 depending upon the current status of the tilt sensor */
00021         if (tilt_sens == HIGH) 
00022         {
00023             light1=ON;  /* Tilt alarm LED is ON */
00024         }
00025         if (tilt_sens == LOW)
00026         {
00027             light1=OFF;  /* Tilt alarm LED is OFF */
00028         }
00029         wait(0.3);  /* Wait 0.3 seconds */
00030     }
00031 }
00032