Function on LEDs

Committer:
PA
Date:
Mon May 28 09:31:32 2012 +0000
Revision:
2:6ef6066f3b6e
Parent:
1:7fd22984c201

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
PA 2:6ef6066f3b6e 1 #include "LEDFunction.h"
PA 1:7fd22984c201 2 #include "mbed.h"
PA 1:7fd22984c201 3
PA 1:7fd22984c201 4 LEDFunction::LEDFunction(PinName pin): _pin(pin){
PA 2:6ef6066f3b6e 5 _pin=0;
PA 1:7fd22984c201 6 Period=16667;
PA 1:7fd22984c201 7 PWMMin=0;
PA 1:7fd22984c201 8 PWMDuty=Period/2;
PA 1:7fd22984c201 9 PWMMax=Period;
PA 1:7fd22984c201 10 Pulse.attach_us(this,&LEDFunction::SigStart,PWMDuty);
PA 1:7fd22984c201 11 }
PA 1:7fd22984c201 12
PA 2:6ef6066f3b6e 13 void LEDFunction::SigStart(){
PA 2:6ef6066f3b6e 14 _pin=1;
PA 2:6ef6066f3b6e 15 PulseEnd.attach_us(this,&LEDFunction::SigStop,PWMDuty);
PA 2:6ef6066f3b6e 16 }
PA 1:7fd22984c201 17
PA 2:6ef6066f3b6e 18 void LEDFunction::SigStop(){
PA 2:6ef6066f3b6e 19 _pin=0;
PA 2:6ef6066f3b6e 20 }
PA 2:6ef6066f3b6e 21
PA 2:6ef6066f3b6e 22 void LEDFunction::write_us(int PosIn){
PA 2:6ef6066f3b6e 23 PWMDuty=PosIn;
PA 2:6ef6066f3b6e 24 if(PosIn<PWMMin){PWMDuty=PWMMin;}
PA 2:6ef6066f3b6e 25 if(PosIn>PWMMax){PWMDuty=PWMMax;}
PA 2:6ef6066f3b6e 26 }
PA 2:6ef6066f3b6e 27
PA 2:6ef6066f3b6e 28 void LEDFunction::duty(float dutIn){
PA 2:6ef6066f3b6e 29 dutIn=Period*dutIn;
PA 2:6ef6066f3b6e 30 int pos=(int)dutIn;
PA 2:6ef6066f3b6e 31 write_us(pos);
PA 2:6ef6066f3b6e 32 }
PA 1:7fd22984c201 33
PA 2:6ef6066f3b6e 34 int LEDFunction::read_us(){
PA 2:6ef6066f3b6e 35 return PWMDuty;
PA 2:6ef6066f3b6e 36 }
PA 1:7fd22984c201 37
PA 2:6ef6066f3b6e 38 void LEDFunction::OnOff(){
PA 2:6ef6066f3b6e 39 if(_pin=0){_pin=1;}
PA 2:6ef6066f3b6e 40 else _pin=0;
PA 2:6ef6066f3b6e 41 }
PA 1:7fd22984c201 42
PA 2:6ef6066f3b6e 43 void LEDFunction::flash(int n){
PA 2:6ef6066f3b6e 44 for(i=0;i<2*n;i++){
PA 2:6ef6066f3b6e 45 _pin=!_pin;
PA 2:6ef6066f3b6e 46 wait(0.5);
PA 2:6ef6066f3b6e 47 }
PA 2:6ef6066f3b6e 48 }