Function on LEDs
Embed:
(wiki syntax)
Show/hide line numbers
LEDFunction.cpp
00001 #include "LEDFunction.h" 00002 #include "mbed.h" 00003 00004 LEDFunction::LEDFunction(PinName pin): _pin(pin){ 00005 _pin=0; 00006 Period=16667; 00007 PWMMin=0; 00008 PWMDuty=Period/2; 00009 PWMMax=Period; 00010 Pulse.attach_us(this,&LEDFunction::SigStart,PWMDuty); 00011 } 00012 00013 void LEDFunction::SigStart(){ 00014 _pin=1; 00015 PulseEnd.attach_us(this,&LEDFunction::SigStop,PWMDuty); 00016 } 00017 00018 void LEDFunction::SigStop(){ 00019 _pin=0; 00020 } 00021 00022 void LEDFunction::write_us(int PosIn){ 00023 PWMDuty=PosIn; 00024 if(PosIn<PWMMin){PWMDuty=PWMMin;} 00025 if(PosIn>PWMMax){PWMDuty=PWMMax;} 00026 } 00027 00028 void LEDFunction::duty(float dutIn){ 00029 dutIn=Period*dutIn; 00030 int pos=(int)dutIn; 00031 write_us(pos); 00032 } 00033 00034 int LEDFunction::read_us(){ 00035 return PWMDuty; 00036 } 00037 00038 void LEDFunction::OnOff(){ 00039 if(_pin=0){_pin=1;} 00040 else _pin=0; 00041 } 00042 00043 void LEDFunction::flash(int n){ 00044 for(i=0;i<2*n;i++){ 00045 _pin=!_pin; 00046 wait(0.5); 00047 } 00048 }
Generated on Wed Jul 13 2022 01:49:34 by
1.7.2