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

Dependencies:   mbed

Fork of nRF_buttons by UCL IoT

main.cpp

Committer:
djmannion
Date:
2014-12-12
Revision:
0:f932320f7606
Child:
1:0133472f4825

File content as of revision 0:f932320f7606:

/*
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 ;)
        }
    }
}