Browse Source

zero duty cycle fix

tags/v0.4.0
Dominik Bartsch 2 years ago
parent
commit
33499beb32
2 changed files with 9 additions and 6 deletions
  1. 4
    3
      include/pwm.h
  2. 5
    3
      src/pwm.cpp

+ 4
- 3
include/pwm.h View File

#define SENSOR1 15 #define SENSOR1 15
#define SENSOR2 12 #define SENSOR2 12


#define INT_TIME 20 // interrupt intervall [ms]
class Treppe { class Treppe {
private: private:
uint8_t stairs; uint8_t stairs;
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
uint16_t idle_brightness = 200;
uint16_t active_brightness = 2048;
uint16_t time_per_stair = 200; // dimmtime per stair [ms]
uint16_t idle_brightness = 0;
uint16_t active_brightness = 1048;


uint8_t direction = 0; uint8_t direction = 0;
uint8_t switch_direction = 0; uint8_t switch_direction = 0;

+ 5
- 3
src/pwm.cpp View File

pwmController.setChannelPWM(led, (uint16_t)startval); pwmController.setChannelPWM(led, (uint16_t)startval);
lastled = led; lastled = led;
current_pwm = startval; current_pwm = startval;
stepsize = 20*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval
stepsize = INT_TIME*abs(stopval - startval)/(float)time_per_stair; // only valid at 1ms function call interval
return 1; return 1;
} }
if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize) return 0;
// todo: duty cycle zero!
if(startval > stopval){ if(startval > stopval){
current_pwm -= stepsize; current_pwm -= stepsize;
} }
} }
Serial.println((uint16_t)current_pwm); Serial.println((uint16_t)current_pwm);
pwmController.setChannelPWM(led, (uint16_t)current_pwm); pwmController.setChannelPWM(led, (uint16_t)current_pwm);
if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize){
if(stopval == 0) pwmController.setChannelPWM(led, 0);
return 0;
}
return 1; return 1;
} }



Loading…
Cancel
Save