test
This commit is contained in:
parent
2b2a135bd5
commit
55ebd21975
3
doku.md
3
doku.md
@ -66,3 +66,6 @@ LED Flickering issue
|
|||||||
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
||||||
|
|
||||||
PlatformIO Library veraltet
|
PlatformIO Library veraltet
|
||||||
|
|
||||||
|
|
||||||
|
###TIMER in OTA unterbrechen !!!!!
|
||||||
|
@ -5,24 +5,39 @@
|
|||||||
class Treppe {
|
class Treppe {
|
||||||
private:
|
private:
|
||||||
uint8_t stairs;
|
uint8_t stairs;
|
||||||
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
uint16_t time_per_stair = 100; // dimmtime per stair [ms]
|
||||||
uint16_t idle_brightness = 200;
|
uint16_t idle_brightness = 25;
|
||||||
uint16_t active_brightness = 2048;
|
uint16_t active_brightness = 500;
|
||||||
|
|
||||||
uint8_t direction = 0;
|
uint8_t direction = 0;
|
||||||
uint8_t state = 0;
|
uint8_t state = 0;
|
||||||
uint8_t switch_state = 0;
|
uint8_t switch_state = 0;
|
||||||
|
|
||||||
|
uint32_t tick = 0;
|
||||||
|
uint32_t stufe = 0;
|
||||||
|
|
||||||
|
uint32_t ticks_treppe = 0;
|
||||||
|
uint32_t ticks_pro_stufe = 0;
|
||||||
|
float differenz_pwm_pro_tick = 0.0;
|
||||||
|
|
||||||
// initialize with i2c-Address 0, use Wire Library
|
// initialize with i2c-Address 0, use Wire Library
|
||||||
PCA9685 pwmController;
|
PCA9685 pwmController;
|
||||||
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
|
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
|
||||||
void ledsequence();
|
void ledsequence();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Treppe(uint8_t _stairs) : stairs(_stairs){}
|
Treppe(uint8_t _stairs) : stairs(_stairs){
|
||||||
|
ticks_pro_stufe = time_per_stair / 20; // [ms]
|
||||||
|
ticks_treppe = ticks_pro_stufe * stairs;
|
||||||
|
|
||||||
|
differenz_pwm_pro_tick = (active_brightness - idle_brightness)
|
||||||
|
/ ticks_pro_stufe;
|
||||||
|
|
||||||
|
}
|
||||||
void task(); // call periodically
|
void task(); // call periodically
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
|
void elelel();
|
||||||
|
|
||||||
// Parameter section
|
// Parameter section
|
||||||
uint16_t setIdle(uint16_t _idle_brightness);
|
uint16_t setIdle(uint16_t _idle_brightness);
|
||||||
|
21
src/main.cpp
21
src/main.cpp
@ -21,7 +21,7 @@ extern "C" {
|
|||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
os_timer_t timer1;
|
os_timer_t timer1;
|
||||||
uint8_t timer_flag = 0;
|
uint8_t timer_flag = 0;
|
||||||
Treppe stairs(13);
|
Treppe stairs(16);
|
||||||
|
|
||||||
// WIFI
|
// WIFI
|
||||||
const char* ssid = STASSID;
|
const char* ssid = STASSID;
|
||||||
@ -102,18 +102,25 @@ void setup() {
|
|||||||
Serial.println("PCA9685 connected !");
|
Serial.println("PCA9685 connected !");
|
||||||
|
|
||||||
os_timer_setfn(&timer1, timerCallback, &timer_flag);
|
os_timer_setfn(&timer1, timerCallback, &timer_flag);
|
||||||
os_timer_arm(&timer1, 20, true);
|
os_timer_arm(&timer1, 200, true);
|
||||||
|
|
||||||
stairs.setState(1);
|
stairs.setState(1);
|
||||||
stairs.setDirection(1);
|
stairs.setDirection(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if(millis() > 25000 && stairs.getState() == 1 && stairs.getDirection() == 1) stairs.setState(0);
|
if(stairs.getState() == 0) {
|
||||||
if(millis() > 45000 && stairs.getDirection() == 1){
|
delay(1000);
|
||||||
stairs.setState(1);
|
stairs.setState(1);
|
||||||
stairs.setDirection(0);
|
stairs.setDirection(!stairs.getDirection());
|
||||||
}
|
}
|
||||||
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
|
|
||||||
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
|
// if(millis() > 25000 && stairs.getState() == 1 && stairs.getDirection() == 1) stairs.setState(0);
|
||||||
|
// if(millis() > 35000 && stairs.getDirection() == 1){
|
||||||
|
// stairs.setState(1);
|
||||||
|
// stairs.setDirection(0);
|
||||||
|
// }
|
||||||
|
TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
|
||||||
|
TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
|
||||||
}
|
}
|
57
src/pwm.cpp
57
src/pwm.cpp
@ -15,7 +15,7 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
|
|||||||
|
|
||||||
static uint8_t lastled = 255;
|
static uint8_t lastled = 255;
|
||||||
static float current_pwm = 0;
|
static float current_pwm = 0;
|
||||||
static float stepsize = 1.0;
|
static float stepsize = 0.5;
|
||||||
if(led != lastled){
|
if(led != lastled){
|
||||||
pwmController.setChannelPWM(led, (uint16_t)startval);
|
pwmController.setChannelPWM(led, (uint16_t)startval);
|
||||||
lastled = led;
|
lastled = led;
|
||||||
@ -44,6 +44,7 @@ void Treppe::ledsequence(){
|
|||||||
static uint8_t finish = 1;
|
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;
|
||||||
status_build |= state;
|
status_build |= state;
|
||||||
if(status_build != status){ // check if any parameter changed
|
if(status_build != status){ // check if any parameter changed
|
||||||
@ -91,10 +92,55 @@ void Treppe::ledsequence(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Treppe::elelel()
|
||||||
|
{
|
||||||
|
if(state) {
|
||||||
|
if(direction) tick++;
|
||||||
|
else tick--;
|
||||||
|
|
||||||
|
// was soll gemacht werden
|
||||||
|
pwmController.setChannelPWM(stufe,
|
||||||
|
(uint16_t) (differenz_pwm_pro_tick * (tick % ticks_pro_stufe) + idle_brightness)
|
||||||
|
);
|
||||||
|
Serial.printf("tick %04d, led %02d:%02d, pwm %4.1f\n",
|
||||||
|
tick,
|
||||||
|
tick / ticks_pro_stufe,
|
||||||
|
(tick % ticks_pro_stufe) ,
|
||||||
|
(differenz_pwm_pro_tick * (tick % ticks_pro_stufe) + idle_brightness)
|
||||||
|
);
|
||||||
|
|
||||||
|
if(tick < 0) { // ziel erreicht
|
||||||
|
tick = 0;
|
||||||
|
state = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(tick == ticks_treppe) {
|
||||||
|
tick = ticks_treppe-1;
|
||||||
|
state = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tick % ticks_pro_stufe == 0) {
|
||||||
|
if(direction) stufe++;
|
||||||
|
else stufe--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if(stufe > stairs || stufe < 0 || tick < 0 || tick > ticks_treppe-1) {
|
||||||
|
// Serial.println("[Treppe] ERROR, Something went wrong !");
|
||||||
|
// state = 0;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
void Treppe::setup(){
|
void Treppe::setup(){
|
||||||
|
Serial.printf("differenz_pwm_pro_tick %f\n", differenz_pwm_pro_tick);
|
||||||
|
|
||||||
pwmController.resetDevices();
|
pwmController.resetDevices();
|
||||||
|
|
||||||
// Deactive PCA9685 due to LED Flickering
|
// Deactivate PCA9685_PhaseBalancer 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);
|
||||||
@ -102,9 +148,14 @@ void Treppe::setup(){
|
|||||||
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);
|
||||||
|
|
||||||
|
for(uint8_t i=0; i<stairs; i++) {
|
||||||
|
pwmController.setChannelPWM(i, idle_brightness);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void Treppe::task(){
|
void Treppe::task(){
|
||||||
ledsequence();
|
//ledsequence();
|
||||||
|
elelel();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t Treppe::setIdle(uint16_t _idle_brightness){
|
uint16_t Treppe::setIdle(uint16_t _idle_brightness){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user