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/Session3/EventQueue/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.
46 lines (36 sloc)
999 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" | |
DigitalOut led1(LED1); | |
DigitalOut led2(LED2); | |
DigitalOut led3(LED3); | |
//Event Queue Version | |
// Create a queue that can hold a maximum of 32 events | |
EventQueue queue(32 * EVENTS_EVENT_SIZE); | |
InterruptIn button(BUTTON1); | |
int buttonState = 0; | |
void led3Event(void){ | |
led3 = !led3; | |
} | |
void ledEvent(void){ | |
//queue.call(led3Event); | |
queue.call(printf, "rise_handler in context %p\n", ThisThread::get_id()); | |
queue.call(led3Event); | |
for (int x=0; x<10; x++){ | |
led2 = !led2; | |
thread_sleep_for(500); | |
} | |
} | |
//Main Program | |
int main() { | |
//Create an empty thread to run objects in the event queue | |
Thread thread; | |
// Start the event queue | |
thread.start(callback(&queue, &EventQueue::dispatch_forever)); | |
//And make the button interrupt add an event to the queue | |
button.rise(queue.event(ledEvent)); | |
while (true) { | |
led1 = !led1; | |
thread_sleep_for(250); | |
//Debug with Light | |
//led3=buttonState; | |
} | |
} |