Sarah Marsh / Blinky

Dependents:   Blinky_Tests Blinky_Tests_GreenTea1

Files at this revision

API Documentation at this revision

Comitter:
sarahmarshy
Date:
Mon Sep 19 16:21:27 2016 +0000
Child:
1:5b51a271d47e
Commit message:
First commit - Blinky library;

Changed in this revision

Blinky.cpp Show annotated file Show diff for this revision Revisions of this file
Blinky.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Blinky.cpp	Mon Sep 19 16:21:27 2016 +0000
@@ -0,0 +1,19 @@
+#include "Blinky.h"
+
+Blinky::Blinky(PinName led, int interval):
+        _led(led), _interval(interval){
+    stop_blink=false;
+}
+void Blinky::start(){
+    _blinker.start(this, &Blinky::blink_led);
+} 
+void Blinky::stop(){
+    stop_blink = true;
+    _blinker.join();
+}  
+void Blinky::blink_led(){
+    while (!stop_blink){
+        _led = !_led;
+        Thread::wait(_interval);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Blinky.h	Mon Sep 19 16:21:27 2016 +0000
@@ -0,0 +1,55 @@
+/* mbed blinky
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef MBED_BLINKY_H
+#define MBED_BLINKY_H
+#include "mbed.h"
+#include "rtos.h"
+
+/** Interface to start a thread that blinks an LED
+ */
+class Blinky {
+public:
+    /** Create a Blinky 
+     *
+     * @param led A PinName, the pin name of the LED to blink
+     * @param interval A int, the interval of time between LED blinks
+     */
+    Blinky(PinName led, int interval);
+    /**Start a thread executing blink_led*/
+    void start();
+    /**Terminate the thread blinking the LED*/
+    void stop();
+    
+protected:
+    /**Function to blink the LED*/
+    void blink_led();
+    /**Thread to execute blink_led*/
+    Thread _blinker;
+    /**LED to blink */
+    DigitalOut _led;
+    /**Interval of time between blinks*/
+    int _interval;
+    /**Bool to stop blinking LED */
+    bool stop_blink;
+};
+#endif
+    
+    
\ No newline at end of file