|
|
|
|
|
|
|
|
static int8_t led = 0; |
|
|
static int8_t led = 0; |
|
|
static uint16_t brightness = 0; |
|
|
static uint16_t brightness = 0; |
|
|
static uint16_t lastbrightness = 0; |
|
|
static uint16_t lastbrightness = 0; |
|
|
static uint8_t finish = 1; |
|
|
|
|
|
static uint16_t status = 0; |
|
|
static uint16_t status = 0; |
|
|
uint16_t status_build = 0; |
|
|
uint16_t status_build = 0; |
|
|
status_build |= direction << 8; |
|
|
status_build |= direction << 8; |
|
|
|
|
|
|
|
|
void Treppe::setup(){ |
|
|
void Treppe::setup(){ |
|
|
pwmController.resetDevices(); |
|
|
pwmController.resetDevices(); |
|
|
|
|
|
|
|
|
// Deactive PCA9685 due to LED Flickering |
|
|
|
|
|
|
|
|
// Deactive PCA9685 Phase Balancer due to LED Flickering |
|
|
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15 |
|
|
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15 |
|
|
// see also lib/PCA9685-Arduin/PCA9685.h:204 |
|
|
// see also lib/PCA9685-Arduin/PCA9685.h:204 |
|
|
pwmController.init(PCA9685_PhaseBalancer_None); |
|
|
pwmController.init(PCA9685_PhaseBalancer_None); |
|
|
pwmController.setPWMFrequency(200); |
|
|
pwmController.setPWMFrequency(200); |
|
|
|
|
|
|
|
|
|
|
|
pinMode(SENSOR1, INPUT); |
|
|
|
|
|
pinMode(SENSOR2, INPUT); |
|
|
Serial.println("Hello from Treppe"); |
|
|
Serial.println("Hello from Treppe"); |
|
|
Serial.print("Treppe: initial parameters: stairs="); |
|
|
Serial.print("Treppe: initial parameters: stairs="); |
|
|
Serial.println(stairs); |
|
|
Serial.println(stairs); |
|
|
} |
|
|
} |
|
|
void Treppe::task(){ |
|
|
void Treppe::task(){ |
|
|
ledsequence(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(finish){ |
|
|
|
|
|
direction = switch_direction; |
|
|
|
|
|
state = switch_state; |
|
|
|
|
|
} |
|
|
|
|
|
static uint8_t last_sensor_state[2] = {0,0}; |
|
|
|
|
|
uint8_t current_sensor_state[2] = {0,0}; |
|
|
|
|
|
current_sensor_state[0] = digitalRead(SENSOR1); |
|
|
|
|
|
current_sensor_state[1] = digitalRead(SENSOR2); |
|
|
|
|
|
|
|
|
|
|
|
if(current_sensor_state[0] && !last_sensor_state[0] && state == 0){ |
|
|
|
|
|
setDirection(1); |
|
|
|
|
|
setState(1); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(current_sensor_state[1] && !last_sensor_state[1] && state == 0){ |
|
|
|
|
|
setDirection(0); |
|
|
|
|
|
setState(1); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// first switch - off approach, use timer later |
|
|
|
|
|
if(!current_sensor_state[0] && last_sensor_state[0] && state == 1){ |
|
|
|
|
|
setDirection(1); |
|
|
|
|
|
setState(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!current_sensor_state[1] && last_sensor_state[1] && state == 1){ |
|
|
|
|
|
setDirection(0); |
|
|
|
|
|
setState(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
last_sensor_state[0] = current_sensor_state[0]; |
|
|
|
|
|
last_sensor_state[1] = current_sensor_state[1]; |
|
|
|
|
|
ledsequence(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint16_t Treppe::setIdle(uint16_t _idle_brightness){ |
|
|
uint16_t Treppe::setIdle(uint16_t _idle_brightness){ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint8_t Treppe::setDirection(uint8_t _direction){ |
|
|
uint8_t Treppe::setDirection(uint8_t _direction){ |
|
|
direction = _direction; |
|
|
|
|
|
|
|
|
switch_direction = _direction; |
|
|
Serial.println("Treppe: Direction changed!"); |
|
|
Serial.println("Treppe: Direction changed!"); |
|
|
|
|
|
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 |
|
|
// to do: implement state command variable to determine dimm-state |
|
|
return direction; |
|
|
|
|
|
|
|
|
return switch_direction; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint8_t Treppe::setState(uint8_t _state){ |
|
|
uint8_t Treppe::setState(uint8_t _state){ |
|
|
if(state == _state) return 1; |
|
|
if(state == _state) return 1; |
|
|
else{ |
|
|
else{ |
|
|
state = _state; |
|
|
|
|
|
Serial.println("Treppe: State changed!"); |
|
|
|
|
|
|
|
|
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; |
|
|
return 0; |
|
|
} |
|
|
} |