Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Task330_polling by
main.cpp@1:e84a51c98d75, 2017-10-23 (annotated)
- Committer:
- noutram
- Date:
- Mon Oct 23 09:47:16 2017 +0000
- Revision:
- 1:e84a51c98d75
- Parent:
- 0:397b84c74d17
- Child:
- 2:4cf6f5cba257
Tidy up and reduce latency
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:397b84c74d17 | 1 | #include "mbed.h" |
noutram | 0:397b84c74d17 | 2 | #include "SWPoll.hpp" |
noutram | 0:397b84c74d17 | 3 | |
noutram | 0:397b84c74d17 | 4 | #define N 1000000 |
noutram | 0:397b84c74d17 | 5 | #define RELEASED 0 |
noutram | 0:397b84c74d17 | 6 | #define PRESSED 1 |
noutram | 0:397b84c74d17 | 7 | |
noutram | 0:397b84c74d17 | 8 | //Function prototypes |
noutram | 0:397b84c74d17 | 9 | void task1(); |
noutram | 0:397b84c74d17 | 10 | void task2(); |
noutram | 0:397b84c74d17 | 11 | |
noutram | 0:397b84c74d17 | 12 | //Hardware objects |
noutram | 0:397b84c74d17 | 13 | DigitalOut red_led(PE_15); //CountUp is in its critical section |
noutram | 0:397b84c74d17 | 14 | DigitalOut yellow_led(PB_10); //CountDown is in its critical section |
noutram | 0:397b84c74d17 | 15 | DigitalOut green_led(PB_11); //counter != 0 |
noutram | 0:397b84c74d17 | 16 | DigitalOut onboardLED(LED1); |
noutram | 0:397b84c74d17 | 17 | |
noutram | 0:397b84c74d17 | 18 | DigitalIn button(USER_BUTTON); |
noutram | 0:397b84c74d17 | 19 | DigitalIn sw1(PE_12); |
noutram | 0:397b84c74d17 | 20 | DigitalIn sw2(PE_14); |
noutram | 0:397b84c74d17 | 21 | |
noutram | 0:397b84c74d17 | 22 | SWPoll switch1(sw1, red_led); |
noutram | 0:397b84c74d17 | 23 | SWPoll switch2(sw2, green_led); |
noutram | 0:397b84c74d17 | 24 | |
noutram | 1:e84a51c98d75 | 25 | //LOOK AT SWPoll.hpp for the definition of the SWPoll class |
noutram | 0:397b84c74d17 | 26 | |
noutram | 0:397b84c74d17 | 27 | int main() { |
noutram | 0:397b84c74d17 | 28 | |
noutram | 0:397b84c74d17 | 29 | //Main uses a Timer |
noutram | 0:397b84c74d17 | 30 | yellow_led = 1; |
noutram | 0:397b84c74d17 | 31 | Timer t; |
noutram | 0:397b84c74d17 | 32 | |
noutram | 0:397b84c74d17 | 33 | //Now loop forever |
noutram | 0:397b84c74d17 | 34 | t.start(); |
noutram | 0:397b84c74d17 | 35 | while(1) { |
noutram | 0:397b84c74d17 | 36 | //Flash the yellow on the "main thread" |
noutram | 0:397b84c74d17 | 37 | if (t.read_ms() >= 500) { |
noutram | 0:397b84c74d17 | 38 | yellow_led = !yellow_led; |
noutram | 0:397b84c74d17 | 39 | t.reset(); |
noutram | 0:397b84c74d17 | 40 | } |
noutram | 0:397b84c74d17 | 41 | switch1.poll(); |
noutram | 0:397b84c74d17 | 42 | switch2.poll(); |
noutram | 0:397b84c74d17 | 43 | |
noutram | 0:397b84c74d17 | 44 | }; |
noutram | 0:397b84c74d17 | 45 | } |
noutram | 0:397b84c74d17 | 46 | |
noutram | 0:397b84c74d17 | 47 |