|
|
@@ -30,7 +30,7 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){ |
|
|
|
else { |
|
|
|
current_pwm += stepsize; |
|
|
|
} |
|
|
|
Serial.println((uint16_t)current_pwm); |
|
|
|
// 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); |
|
|
@@ -60,46 +60,40 @@ void Treppe::ledsequence(){ |
|
|
|
lastbrightness = active_brightness; |
|
|
|
} |
|
|
|
status = status_build; // set parameter memory |
|
|
|
Serial.print("----Status Changed! onoff: "); |
|
|
|
Serial.print(state); |
|
|
|
Serial.print(" dir: "); |
|
|
|
Serial.println(direction); |
|
|
|
|
|
|
|
Serial.printf("----Status Changed! onoff: %d, dir: %d\n", state, direction); |
|
|
|
} |
|
|
|
if(!finish){ // finish == 0 -> action pending |
|
|
|
if(!softstart_led(led,lastbrightness, brightness)){ |
|
|
|
Serial.print("one LED finished: "); |
|
|
|
Serial.print(led); |
|
|
|
Serial.print(" last: "); |
|
|
|
Serial.print(lastbrightness); |
|
|
|
Serial.print(" curr: "); |
|
|
|
Serial.println(brightness); |
|
|
|
if(direction){ |
|
|
|
led++; |
|
|
|
if(led >= stairs) { |
|
|
|
if(!softstart_led(led,lastbrightness, brightness)){ |
|
|
|
Serial.printf("one LED finished: led: %d, last: %d, curr %d\n", |
|
|
|
led, lastbrightness, brightness); |
|
|
|
|
|
|
|
if(direction){ |
|
|
|
led++; |
|
|
|
if(led >= stairs) |
|
|
|
finish = 1; |
|
|
|
} |
|
|
|
else{ |
|
|
|
led--; |
|
|
|
if(led < 0) |
|
|
|
finish = 1; |
|
|
|
//lastbrightness = brightness; |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
led--; |
|
|
|
if(led < 0){ |
|
|
|
//lastbrightness = brightness; |
|
|
|
finish = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Treppe::task_2() |
|
|
|
void Treppe::rampe() |
|
|
|
{ |
|
|
|
if(state) { |
|
|
|
finish = 0; |
|
|
|
state = 0; // set parameter memory |
|
|
|
} |
|
|
|
|
|
|
|
if(!finish) { |
|
|
|
if(direction) { // aufwärts |
|
|
|
if(tick >= ticks_treppe-1) { // ziel erreicht |
|
|
|
Serial.println("[Treppe] oberster tick !"); |
|
|
|
state = 0; |
|
|
|
finish = 1; |
|
|
|
return; |
|
|
|
} |
|
|
|
tick++; // eins hoch |
|
|
@@ -107,17 +101,25 @@ void Treppe::task_2() |
|
|
|
else { // abwärts |
|
|
|
if(tick <= 0) { // ziel erreicht |
|
|
|
Serial.println("[Treppe] unterster tick !"); |
|
|
|
state = 0; |
|
|
|
finish = 1; |
|
|
|
return; |
|
|
|
} |
|
|
|
tick--; // eins runter |
|
|
|
} |
|
|
|
|
|
|
|
stufe = tick / ticks_pro_stufe; |
|
|
|
float new_pwm = differenz_pwm_pro_tick * (tick - ticks_pro_stufe*stufe); |
|
|
|
if(direction) |
|
|
|
new_pwm += differenz_pwm_pro_tick; |
|
|
|
new_pwm += idle_brightness; |
|
|
|
|
|
|
|
float new_pwm = 0.0; |
|
|
|
if(an_aus) { |
|
|
|
new_pwm = differenz_pwm_pro_tick * (tick - ticks_pro_stufe*stufe); |
|
|
|
new_pwm += idle_brightness; |
|
|
|
if(direction) new_pwm += differenz_pwm_pro_tick; |
|
|
|
} |
|
|
|
else { |
|
|
|
new_pwm = active_brightness - differenz_pwm_pro_tick * (tick - ticks_pro_stufe*stufe); |
|
|
|
new_pwm += idle_brightness; |
|
|
|
if(direction) new_pwm -= differenz_pwm_pro_tick; |
|
|
|
} |
|
|
|
|
|
|
|
pwmController.setChannelPWM(stufe, (uint16_t) new_pwm); |
|
|
|
Serial.printf("tick %04u, led %02d:%02u, pwm %4.1f\n", |
|
|
@@ -129,12 +131,6 @@ void Treppe::task_2() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// if(stufe > stairs || stufe < 0 || tick < 0 || tick > ticks_treppe-1) { |
|
|
|
// Serial.println("[Treppe] ERROR, Something went wrong !"); |
|
|
|
// state = 0; |
|
|
|
// return; |
|
|
|
// } |
|
|
|
|
|
|
|
void Treppe::setup(){ |
|
|
|
Serial.printf("differenz_pwm_pro_tick %f\n", differenz_pwm_pro_tick); |
|
|
|
|
|
|
@@ -166,30 +162,38 @@ void Treppe::task(){ |
|
|
|
current_sensor_state[1] = digitalRead(SENSOR2); |
|
|
|
|
|
|
|
if(current_sensor_state[0] && !last_sensor_state[0] && state == 0){ |
|
|
|
setTick(0); |
|
|
|
setAnAus(1); |
|
|
|
setDirection(1); |
|
|
|
setState(1); |
|
|
|
} |
|
|
|
|
|
|
|
if(current_sensor_state[1] && !last_sensor_state[1] && state == 0){ |
|
|
|
setTick(0); |
|
|
|
setAnAus(0); |
|
|
|
setDirection(0); |
|
|
|
setState(1); |
|
|
|
} |
|
|
|
|
|
|
|
// first switch - off approach, use timer later |
|
|
|
if(!current_sensor_state[0] && last_sensor_state[0] && state == 1){ |
|
|
|
setTick(ticks_treppe); |
|
|
|
setAnAus(1); |
|
|
|
setDirection(1); |
|
|
|
setState(0); |
|
|
|
} |
|
|
|
|
|
|
|
if(!current_sensor_state[1] && last_sensor_state[1] && state == 1){ |
|
|
|
setTick(ticks_treppe); |
|
|
|
setAnAus(1); |
|
|
|
setDirection(0); |
|
|
|
setState(0); |
|
|
|
} |
|
|
|
|
|
|
|
last_sensor_state[0] = current_sensor_state[0]; |
|
|
|
last_sensor_state[1] = current_sensor_state[1]; |
|
|
|
ledsequence(); |
|
|
|
|
|
|
|
ledsequence(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@@ -209,22 +213,20 @@ uint16_t Treppe::setTime(uint16_t _time_per_stair){ |
|
|
|
return time_per_stair; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t Treppe::setDirection(uint8_t _direction){ |
|
|
|
void Treppe::setDirection(uint8_t _direction){ |
|
|
|
switch_direction = _direction; |
|
|
|
Serial.println("Treppe: Direction changed!"); |
|
|
|
Serial.printf("Treppe: switch_direction=%d!\n", switch_direction); |
|
|
|
if(finish) Serial.println("apply direction request immediately"); |
|
|
|
else Serial.println("currently active, dir change afterwards"); |
|
|
|
// to do: implement state command variable to determine dimm-state |
|
|
|
return switch_direction; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t Treppe::setState(uint8_t _state){ |
|
|
|
if(state == _state) return 1; |
|
|
|
else{ |
|
|
|
switch_state = _state; |
|
|
|
Serial.println("Treppe: State Request changed!"); |
|
|
|
if(finish) Serial.println("apply state request immediately"); |
|
|
|
else Serial.println("currently active, state changes after activity"); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
void Treppe::setState(uint8_t _state){ |
|
|
|
if(state == _state) return; |
|
|
|
else { |
|
|
|
switch_state = _state; |
|
|
|
Serial.printf("Treppe: switch_state=%d!\n", switch_state); |
|
|
|
if(finish) Serial.println("apply state request immediately"); |
|
|
|
else Serial.println("currently active, state changes after activity"); |
|
|
|
} |
|
|
|
} |