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
52 lines (35 sloc) 961 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;
}
void flash(DigitalOut theLed, int sleep){
theLed = 1;
thread_sleep_for(sleep);
theLed = 0;
thread_sleep_for(sleep);
}
int main() {
// put your setup code here, to run once:
//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:
//Setup the LED1 pin to be a digital output called ledOne
DigitalOut ledOne(LED1);
//Print the State of our button
printf("Button State is %d\n", buttonState);
//Is the Button Pressed
if (buttonState) {
flash(ledOne, 2000);
}
else{
flash(ledOne, 500);
}
}
}