Andy Pomfret
/
UoY-32C-lab7-class
Template project for University of York ELE00032C Lab 7
Diff: main.cpp
- Revision:
- 1:dc9328c6acaa
- Parent:
- 0:77209603a6fe
--- 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); }