Given LED PinName and blink interval, spawns a thread that blinks that LED at the specified interval
Dependents: Blinky_Tests Blinky_Tests_GreenTea1
Blinky.cpp@1:5b51a271d47e, 2016-09-19 (annotated)
- Committer:
- sarahmarshy
- Date:
- Mon Sep 19 19:52:49 2016 +0000
- Revision:
- 1:5b51a271d47e
- Parent:
- 0:8fe86312b714
Force led low in constructor;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sarahmarshy | 0:8fe86312b714 | 1 | #include "Blinky.h" |
sarahmarshy | 0:8fe86312b714 | 2 | |
sarahmarshy | 0:8fe86312b714 | 3 | Blinky::Blinky(PinName led, int interval): |
sarahmarshy | 0:8fe86312b714 | 4 | _led(led), _interval(interval){ |
sarahmarshy | 0:8fe86312b714 | 5 | stop_blink=false; |
sarahmarshy | 1:5b51a271d47e | 6 | _led=1; |
sarahmarshy | 0:8fe86312b714 | 7 | } |
sarahmarshy | 0:8fe86312b714 | 8 | void Blinky::start(){ |
sarahmarshy | 0:8fe86312b714 | 9 | _blinker.start(this, &Blinky::blink_led); |
sarahmarshy | 0:8fe86312b714 | 10 | } |
sarahmarshy | 0:8fe86312b714 | 11 | void Blinky::stop(){ |
sarahmarshy | 0:8fe86312b714 | 12 | stop_blink = true; |
sarahmarshy | 0:8fe86312b714 | 13 | _blinker.join(); |
sarahmarshy | 0:8fe86312b714 | 14 | } |
sarahmarshy | 0:8fe86312b714 | 15 | void Blinky::blink_led(){ |
sarahmarshy | 0:8fe86312b714 | 16 | while (!stop_blink){ |
sarahmarshy | 0:8fe86312b714 | 17 | _led = !_led; |
sarahmarshy | 0:8fe86312b714 | 18 | Thread::wait(_interval); |
sarahmarshy | 0:8fe86312b714 | 19 | } |
sarahmarshy | 0:8fe86312b714 | 20 | } |