Function on LEDs
LEDFunction.cpp@0:38ffbf6895c1, 2012-05-28 (annotated)
- Committer:
- PA
- Date:
- Mon May 28 02:58:18 2012 +0000
- Revision:
- 0:38ffbf6895c1
- Child:
- 1:7fd22984c201
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PA | 0:38ffbf6895c1 | 1 | #include "LEDFunction.h" |
PA | 0:38ffbf6895c1 | 2 | #include "mbed.h" |
PA | 0:38ffbf6895c1 | 3 | |
PA | 0:38ffbf6895c1 | 4 | LEDFunction::LEDFunction(PinName pin): _pin(pin){ |
PA | 0:38ffbf6895c1 | 5 | _pin = 0; |
PA | 0:38ffbf6895c1 | 6 | Period=16667; |
PA | 0:38ffbf6895c1 | 7 | PWMMin=0; |
PA | 0:38ffbf6895c1 | 8 | PWMDuty=Period/2; |
PA | 0:38ffbf6895c1 | 9 | PWMMax=Period; |
PA | 0:38ffbf6895c1 | 10 | Pulse.attach_us(this,&LEDFunction::SigStart,PWMDuty); |
PA | 0:38ffbf6895c1 | 11 | |
PA | 0:38ffbf6895c1 | 12 | void LEDFunction::OnOff(){ |
PA | 0:38ffbf6895c1 | 13 | if(_pin == 0){ |
PA | 0:38ffbf6895c1 | 14 | _pin = 1; |
PA | 0:38ffbf6895c1 | 15 | } |
PA | 0:38ffbf6895c1 | 16 | else _pin = 0; |
PA | 0:38ffbf6895c1 | 17 | } |
PA | 0:38ffbf6895c1 | 18 | |
PA | 0:38ffbf6895c1 | 19 | void LEDFunction::SigStart(){ |
PA | 0:38ffbf6895c1 | 20 | _pin=1; |
PA | 0:38ffbf6895c1 | 21 | PulseEnd.attach_us(this,&LEDFunction::SigStop,PWMDuty); |
PA | 0:38ffbf6895c1 | 22 | } |
PA | 0:38ffbf6895c1 | 23 | |
PA | 0:38ffbf6895c1 | 24 | void LEDFunction::SigStop(){ |
PA | 0:38ffbf6895c1 | 25 | _Pin=0; |
PA | 0:38ffbf6895c1 | 26 | } |
PA | 0:38ffbf6895c1 | 27 | |
PA | 0:38ffbf6895c1 | 28 | void LEDFunction::write_us(int PosIn){ |
PA | 0:38ffbf6895c1 | 29 | PWMDuty=PosIn; |
PA | 0:38ffbf6895c1 | 30 | if(PosIn<PWMMin){PWMDuty=PWMMin;} |
PA | 0:38ffbf6895c1 | 31 | if(PosIn>PWMMax){PWMDuty=PWMMax;} |
PA | 0:38ffbf6895c1 | 32 | } |
PA | 0:38ffbf6895c1 | 33 | |
PA | 0:38ffbf6895c1 | 34 | void LEDFunction::duty(float dutIn){ |
PA | 0:38ffbf6895c1 | 35 | dutIn=Period*dutIn; |
PA | 0:38ffbf6895c1 | 36 | int pos=(int)dutIn; |
PA | 0:38ffbf6895c1 | 37 | write_us(pos); |
PA | 0:38ffbf6895c1 | 38 | } |
PA | 0:38ffbf6895c1 | 39 | |
PA | 0:38ffbf6895c1 | 40 | int LEDFunction::read_us(){ |
PA | 0:38ffbf6895c1 | 41 | return PWMDuty; |
PA | 0:38ffbf6895c1 | 42 | } |