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

@@ -5,12 +5,13 @@
#define SENSOR1 15
#define SENSOR2 12

#define INT_TIME 20 // interrupt intervall [ms]
class Treppe {
private:
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 switch_direction = 0;

+ 5
- 3
src/pwm.cpp View File

@@ -20,12 +20,10 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
pwmController.setChannelPWM(led, (uint16_t)startval);
lastled = led;
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;
}
if(current_pwm > stopval - stepsize && current_pwm < stopval + stepsize) return 0;
// todo: duty cycle zero!
if(startval > stopval){
current_pwm -= stepsize;
}
@@ -34,6 +32,10 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
}
Serial.println((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;
}


Loading…
Cancel
Save