Skip to content
Permalink
0ec2f9b425
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
45 lines (35 sloc) 959 Bytes
#include <mbed.h>
// Variable to hold button State, this needs to be globally avaialable
int buttonState;
// Hander Function for our Buton Press
void handler(){
printf("Update Button State\n");
buttonState = !buttonState;
}
int main() {
// put your setup code here, to run once:
//Setup the LED1 pin to be a digital output called ledOne
DigitalOut ledOne(LED1);
//Setup the User Buton as an Input
InterruptIn theButton(USER_BUTTON);
//Bind the interupt to a function
theButton.rise(&handler);
while(1) {
// put your main code here, to run repeatedly:
//Print the State of our button
printf("Button State is %d\n", buttonState);
//Is the Button Pressed
if (buttonState) {
ledOne = 1;
thread_sleep_for(2000);
ledOne = 0;
thread_sleep_for(2000);
}
else{
ledOne = 1;
thread_sleep_for(500);
ledOne = 0;
thread_sleep_for(500);
}
}
}