Function on LEDs

Files at this revision

API Documentation at this revision

Comitter:
PA
Date:
Mon May 28 09:31:32 2012 +0000
Parent:
1:7fd22984c201
Commit message:

Changed in this revision

LEDFunction.cpp Show annotated file Show diff for this revision Revisions of this file
LEDFunction.h Show annotated file Show diff for this revision Revisions of this file
--- a/LEDFunction.cpp	Mon May 28 06:59:21 2012 +0000
+++ b/LEDFunction.cpp	Mon May 28 09:31:32 2012 +0000
@@ -1,8 +1,8 @@
+#include "LEDFunction.h"
 #include "mbed.h"
-#include "LEDFunction.h"
 
 LEDFunction::LEDFunction(PinName pin): _pin(pin){
-    _pin = 0;
+    _pin=0;
     Period=16667;
     PWMMin=0;
     PWMDuty=Period/2;
@@ -10,39 +10,39 @@
     Pulse.attach_us(this,&LEDFunction::SigStart,PWMDuty);
 }
 
-    void LEDFunction::SigStart(){
-        _pin=1;
-        PulseEnd.attach_us(this,&LEDFunction::SigStop,PWMDuty);   
-    }
+void LEDFunction::SigStart(){
+    _pin=1;
+    PulseEnd.attach_us(this,&LEDFunction::SigStop,PWMDuty);   
+}
  
-    void LEDFunction::SigStop(){
-        _pin=0;
-    }
- 
-    void LEDFunction::write_us(int PosIn){
-        PWMDuty=PosIn;
-        if(PosIn<PWMMin){PWMDuty=PWMMin;}
-        if(PosIn>PWMMax){PWMDuty=PWMMax;}
-    }
+void LEDFunction::SigStop(){
+    _pin=0;
+}
+
+void LEDFunction::write_us(int PosIn){
+    PWMDuty=PosIn;
+    if(PosIn<PWMMin){PWMDuty=PWMMin;}
+    if(PosIn>PWMMax){PWMDuty=PWMMax;}
+}
+
+void LEDFunction::duty(float dutIn){
+    dutIn=Period*dutIn;
+    int pos=(int)dutIn;
+    write_us(pos);
+}
      
-    void LEDFunction::duty(float dutIn){
-       dutIn=Period*dutIn;
-       int pos=(int)dutIn;
-       write_us(pos);
-    }
-     
-    int LEDFunction::read_us(){
-       return PWMDuty;
-    }
+int LEDFunction::read_us(){
+    return PWMDuty;
+}
     
-    void LEDFunction::OnOff(){
-        if(_pin=0){_pin=1;}
-        else _pin=0;
-    }
+void LEDFunction::OnOff(){
+    if(_pin=0){_pin=1;}
+    else _pin=0;
+}
     
-    void LEDFunction::flash(int n){
-        for(i=0;i<2*n;i++){
-            _pin=!_pin;
-            wait(0.5);
-        }
-    }
\ No newline at end of file
+void LEDFunction::flash(int n){
+    for(i=0;i<2*n;i++){
+        _pin=!_pin;
+        wait(0.5);
+    }
+}
\ No newline at end of file
--- a/LEDFunction.h	Mon May 28 06:59:21 2012 +0000
+++ b/LEDFunction.h	Mon May 28 09:31:32 2012 +0000
@@ -1,25 +1,21 @@
-#include "mbed.h"
-
 #ifndef MBED_LEDFUNCTION_H
 #define MBED_LEDFUNCTION_H
- 
+#include "mbed.h"
 
- 
 class LEDFunction{
- 
+
 public:
     LEDFunction(PinName);
     void write_us(int);
     void duty(float);
-    int read_us();
     void OnOff();
     void flash(int);
-    
-    
- private:
+    int read_us();
+
+private:
     void SigStart();
     void SigStop();
-    DigitalOut _pin;
+    DigitalInOut _pin;
     int Period;
     int PWMDuty;
     int PWMMin;
@@ -27,9 +23,6 @@
     int i;
     Ticker Pulse;
     Timeout PulseEnd;
- 
- };
-    
-    
-#endif
-    
\ No newline at end of file
+};
+
+#endif
\ No newline at end of file