Function on LEDs

Committer:
PA
Date:
Mon May 28 06:59:21 2012 +0000
Revision:
1:7fd22984c201
Parent:
0:38ffbf6895c1
Child:
2:6ef6066f3b6e

        

Who changed what in which revision?

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