Code to demonstrate use of the two buttons to toggle LED's

Dependencies:   mbed

Fork of nRF_buttons by UCL IoT

Revision:
0:f932320f7606
Child:
1:0133472f4825
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Dec 12 09:01:15 2014 +0000
@@ -0,0 +1,34 @@
+/*
+This code uses the button1 to toggle LED1 and button2 to toggle LED2 
+Author: Dan M
+Date Created: 12.12.2014
+Last Update: 12.12.2014
+*/
+#include "mbed.h"
+//Define pin names and numbers ( I know these probably aren't needed but I put them in to demonstrate pin numbers)
+#define LED1 p18
+#define LED2 p19
+#define SW1 p16
+#define SW2 p17
+//Instantiate IO objects
+DigitalOut led_1(LED1);
+DigitalOut led_2(LED2);
+DigitalIn  sw_1(SW1);
+DigitalIn  sw_2(SW2);
+
+int main() {
+    led_1=0;
+    led_2=0;
+    while(1) {
+        if(!sw_1)
+        {
+            led_1=!led_1; 
+            wait(0.25);   //Button Debounce ;)
+        }
+        if(!sw_2)
+        {
+            led_2=!led_2;
+            wait(0.25);   //Button Debounce ;)
+        }
+    }
+}