elec350

Dependencies:   mbed

Fork of elec350 by Bob Merrison-Hort

Committer:
rmerrisonhort
Date:
Tue Nov 10 20:12:21 2015 +0000
Revision:
15:c1362c12a896
Parent:
7:aa63d1e53be6
Added isOn to Led class.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rmerrisonhort 0:753cf4c2738f 1 #include "led.h"
rmerrisonhort 0:753cf4c2738f 2 #include <vector>
rmerrisonhort 0:753cf4c2738f 3
rmerrisonhort 15:c1362c12a896 4 // Led class contructor.
rmerrisonhort 0:753cf4c2738f 5 Led::Led(string name) {
rmerrisonhort 0:753cf4c2738f 6 if (name == "red") {
rmerrisonhort 0:753cf4c2738f 7 this->pinName = PD_14;
rmerrisonhort 0:753cf4c2738f 8 } else if (name == "green") {
rmerrisonhort 0:753cf4c2738f 9 this->pinName = PD_12;
rmerrisonhort 0:753cf4c2738f 10 } else if (name == "orange") {
rmerrisonhort 0:753cf4c2738f 11 this->pinName = PD_13;
rmerrisonhort 0:753cf4c2738f 12 } else if (name == "blue") {
rmerrisonhort 0:753cf4c2738f 13 this->pinName = PD_15;
rmerrisonhort 0:753cf4c2738f 14 }
rmerrisonhort 0:753cf4c2738f 15
rmerrisonhort 0:753cf4c2738f 16 this->pin = new DigitalOut(this->pinName);
rmerrisonhort 15:c1362c12a896 17 this->isOn = false;
rmerrisonhort 0:753cf4c2738f 18 }
rmerrisonhort 0:753cf4c2738f 19
rmerrisonhort 15:c1362c12a896 20 // Method to switch the LED on.
rmerrisonhort 7:aa63d1e53be6 21 void Led::On() {
rmerrisonhort 0:753cf4c2738f 22 this->pin->write(1);
rmerrisonhort 15:c1362c12a896 23 this->isOn = true;
rmerrisonhort 0:753cf4c2738f 24 }
rmerrisonhort 0:753cf4c2738f 25
rmerrisonhort 15:c1362c12a896 26 // Method to switch the LED off.
rmerrisonhort 7:aa63d1e53be6 27 void Led::Off() {
rmerrisonhort 0:753cf4c2738f 28 this->pin->write(0);
rmerrisonhort 15:c1362c12a896 29 this->isOn = false;
rmerrisonhort 15:c1362c12a896 30 }
rmerrisonhort 15:c1362c12a896 31
rmerrisonhort 15:c1362c12a896 32 // Method to get the current state of the LED.
rmerrisonhort 15:c1362c12a896 33 // (true=on, false=off).
rmerrisonhort 15:c1362c12a896 34 bool Led::getIsOn() {
rmerrisonhort 15:c1362c12a896 35 return this->isOn;
rmerrisonhort 15:c1362c12a896 36 }
rmerrisonhort 15:c1362c12a896 37