Andy Pomfret
/
UoY-32C-lab7-class
Template project for University of York ELE00032C Lab 7
main.cpp
- Committer:
- ajp109
- Date:
- 2021-02-04
- Revision:
- 1:dc9328c6acaa
- Parent:
- 0:77209603a6fe
File content as of revision 1:dc9328c6acaa:
#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() { green.start(); red.start(); while (true); }