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

Dependencies:   mbed

Revision:
0:bce3540c3f6f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jun 29 12:26:37 2015 +0000
@@ -0,0 +1,32 @@
+#include "mbed.h"
+/* This program generates a tilt alarm using LED1 */
+
+/* Define some useful constants */
+#define ON 1
+#define OFF 0
+#define HIGH 1
+#define LOW 0
+
+/* Use LED1 */
+DigitalOut light1(LED1);
+/* Use pin 5 for the tilt sensor */
+DigitalIn tilt_sens(p5); 
+
+/* Main loop */
+int main() 
+{
+    while(1) 
+    {
+        /* Set LED1 depending upon the current status of the tilt sensor */
+        if (tilt_sens == HIGH) 
+        {
+            light1=ON;  /* Tilt alarm LED is ON */
+        }
+        if (tilt_sens == LOW)
+        {
+            light1=OFF;  /* Tilt alarm LED is OFF */
+        }
+        wait(0.3);  /* Wait 0.3 seconds */
+    }
+}
+