Permalink
Cannot retrieve contributors at this time
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?
7148_Labs_2223/Lab3_Functions/src/main.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
52 lines (35 sloc)
961 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} | |
} |