Oscar Schofield / Mbed 2 deprecated Elec350_OBS

Dependencies:   mbed

Committer:
Oschofield
Date:
Fri Nov 27 12:37:31 2015 +0000
Revision:
20:85a44ddbdc41
Parent:
19:6ad1702c5d90
Converted Toggle() to allow for status to be returned from the function

Who changed what in which revision?

UserRevisionLine numberNew 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 20:85a44ddbdc41 39 bool Led::Toggle(){
Oschofield 20:85a44ddbdc41 40 if(this -> Status()){ // Checks if the current Pin out Status is on (true)
Oschofield 20:85a44ddbdc41 41 this->Off(); // turn LED off
Oschofield 20:85a44ddbdc41 42 return *LedOut; // return LED Status as Off
Oschofield 20:85a44ddbdc41 43 }
Oschofield 20:85a44ddbdc41 44 else{ // If Led is off
Oschofield 20:85a44ddbdc41 45 this->On(); // Turn Led on
Oschofield 20:85a44ddbdc41 46 return *LedOut; // return LED Status as On
Oschofield 20:85a44ddbdc41 47 }
Oschofield 18:106b4cb3a647 48 }