Skip to content
Permalink
e1a1cdea39
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
46 lines (36 sloc) 999 Bytes
#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;
}
}