Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
led.cpp@18:106b4cb3a647, 2015-11-27 (annotated)
- Committer:
- Oschofield
- Date:
- Fri Nov 27 10:19:57 2015 +0000
- Revision:
- 18:106b4cb3a647
- Parent:
- 17:d46ebce20be0
- Child:
- 19:6ad1702c5d90
Added Toggle
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Oschofield | 1:16b0f2898739 | 1 | #include "led.h" //include header file |
Oschofield | 1:16b0f2898739 | 2 | |
Oschofield | 1:16b0f2898739 | 3 | //constructor |
Oschofield | 1:16b0f2898739 | 4 | |
Oschofield | 1:16b0f2898739 | 5 | Led::Led(string s){ //Constructor implementation |
Oschofield | 1:16b0f2898739 | 6 | if(s == "red") |
Oschofield | 1:16b0f2898739 | 7 | pin = PD_14; |
Oschofield | 1:16b0f2898739 | 8 | |
Oschofield | 1:16b0f2898739 | 9 | else if(s == "blue") |
Oschofield | 1:16b0f2898739 | 10 | pin = PD_15; |
Oschofield | 1:16b0f2898739 | 11 | |
Oschofield | 1:16b0f2898739 | 12 | else if(s == "green") |
Oschofield | 1:16b0f2898739 | 13 | pin = PD_12; |
Oschofield | 1:16b0f2898739 | 14 | |
Oschofield | 1:16b0f2898739 | 15 | else if(s == "orange") |
Oschofield | 1:16b0f2898739 | 16 | pin = PD_13; |
Oschofield | 1:16b0f2898739 | 17 | LedOut = new DigitalOut(pin); |
Oschofield | 1:16b0f2898739 | 18 | } |
Oschofield | 1:16b0f2898739 | 19 | |
Oschofield | 1:16b0f2898739 | 20 | void Led::On(){ |
Oschofield | 1:16b0f2898739 | 21 | LedOut -> write(1); |
Oschofield | 1:16b0f2898739 | 22 | } |
Oschofield | 1:16b0f2898739 | 23 | |
Oschofield | 1:16b0f2898739 | 24 | void Led::Off(){ |
Oschofield | 1:16b0f2898739 | 25 | LedOut -> write(0); |
Oschofield | 1:16b0f2898739 | 26 | } |
Oschofield | 1:16b0f2898739 | 27 | |
Oschofield | 1:16b0f2898739 | 28 | void Led::Flash(float Delay){ |
Oschofield | 1:16b0f2898739 | 29 | wait(Delay); |
Oschofield | 1:16b0f2898739 | 30 | On(); |
Oschofield | 1:16b0f2898739 | 31 | wait(Delay); |
Oschofield | 1:16b0f2898739 | 32 | Off(); |
Oschofield | 17:d46ebce20be0 | 33 | } |
Oschofield | 17:d46ebce20be0 | 34 | |
Oschofield | 17:d46ebce20be0 | 35 | bool Led::Status(){ |
Oschofield | 17:d46ebce20be0 | 36 | return *LedOut; |
Oschofield | 18:106b4cb3a647 | 37 | } |
Oschofield | 18:106b4cb3a647 | 38 | |
Oschofield | 18:106b4cb3a647 | 39 | void Led::Toggle(){ |
Oschofield | 18:106b4cb3a647 | 40 | if(this -> Status()){ |
Oschofield | 18:106b4cb3a647 | 41 | this->Off(); |
Oschofield | 18:106b4cb3a647 | 42 | }else{ |
Oschofield | 18:106b4cb3a647 | 43 | this->On(); |
Oschofield | 18:106b4cb3a647 | 44 | } |
Oschofield | 18:106b4cb3a647 | 45 | } |