Example solution of rapid polling (with C++)
Fork of Task330_polling by
main.cpp
- Committer:
- noutram
- Date:
- 2019-09-18
- Revision:
- 2:4cf6f5cba257
- Parent:
- 1:e84a51c98d75
File content as of revision 2:4cf6f5cba257:
#include "mbed.h"
#include "SWPoll.hpp"
#define N 1000000
#define RELEASED 0
#define PRESSED 1
//Hardware objects
DigitalOut red_led(PE_15); //CountUp is in its critical section
DigitalOut yellow_led(PB_10); //CountDown is in its critical section
DigitalOut green_led(PB_11); //counter != 0
DigitalOut onboardLED(LED1);
DigitalIn button(USER_BUTTON);
DigitalIn sw1(PE_12);
DigitalIn sw2(PE_14);
SWPoll switch1(sw1, red_led);
SWPoll switch2(sw2, green_led);
//LOOK AT SWPoll.hpp for the definition of the SWPoll class
int main() {
//Main uses a Timer
yellow_led = 1;
Timer t;
//Now loop forever
t.start();
while(1) {
//Flash the yellow on the "main thread"
if (t.read_ms() >= 500) {
yellow_led = !yellow_led;
t.reset();
}
switch1.poll();
switch2.poll();
};
}
