Andy Pomfret
/
UoY-32C-lab7-class
Template project for University of York ELE00032C Lab 7
Revision 1:dc9328c6acaa, committed 2021-02-04
- Comitter:
- ajp109
- Date:
- Thu Feb 04 17:15:15 2021 +0000
- Parent:
- 0:77209603a6fe
- Commit message:
- Initial commit (lab7-class)
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 77209603a6fe -r dc9328c6acaa main.cpp --- a/main.cpp Mon Jan 11 11:28:11 2021 +0000 +++ b/main.cpp Thu Feb 04 17:15:15 2021 +0000 @@ -1,15 +1,46 @@ #include "mbed.h" +class Flasher { + + DigitalOut pin_; + Ticker ticker_; + Timeout timeout_; + chrono::milliseconds onTime_; + chrono::milliseconds offTime_; + + void on() { + pin_ = true; + timeout_.attach(callback(this, &Flasher::off), onTime_); + } + + void off() { + pin_ = false; + } + +public: + + Flasher(PinName pin, chrono::milliseconds const & onTime, chrono::milliseconds const & offTime) : + pin_(pin), onTime_(onTime), offTime_(offTime) { } + + void start() { + ticker_.attach(callback(this, &Flasher::on), onTime_ + offTime_); + } + + void stop() { + ticker_.detach(); + } + +}; + + + + +Flasher green(D2, 500ms, 2500ms); +Flasher red(D3, 300ms, 1700ms); + int main() { - int x = 4; - x = 6; - int y; - y = 2*x; - x = 7; - - printf("x:%d y:%d\n", x, y); - - // Do nothing, forever... + green.start(); + red.start(); while (true); }