Template project for University of York ELE00032C Lab 7

Dependencies:   UoY-serial

Files at this revision

API Documentation at this revision

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
--- 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);
 }