Browse Source

test

tags/FSM1.0
Simon Schmidt 3 years ago
parent
commit
55ebd21975
4 changed files with 92 additions and 16 deletions
  1. 3
    0
      doku.md
  2. 21
    6
      include/pwm.h
  3. 14
    7
      src/main.cpp
  4. 54
    3
      src/pwm.cpp

+ 3
- 0
doku.md View File

@@ -66,3 +66,6 @@ LED Flickering issue
https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15

PlatformIO Library veraltet


###TIMER in OTA unterbrechen !!!!!

+ 21
- 6
include/pwm.h View File

@@ -3,26 +3,41 @@
#include "PCA9685.h"

class Treppe {
private:
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 = 100; // dimmtime per stair [ms]
uint16_t idle_brightness = 25;
uint16_t active_brightness = 500;

uint8_t direction = 0;
uint8_t 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
PCA9685 pwmController;
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
void ledsequence();

public:
Treppe(uint8_t _stairs) : stairs(_stairs){}
public:
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 setup();
void elelel();

// Parameter section
uint16_t setIdle(uint16_t _idle_brightness);

+ 14
- 7
src/main.cpp View File

@@ -21,7 +21,7 @@ extern "C" {
#include "pwm.h"
os_timer_t timer1;
uint8_t timer_flag = 0;
Treppe stairs(13);
Treppe stairs(16);

// WIFI
const char* ssid = STASSID;
@@ -102,18 +102,25 @@ void setup() {
Serial.println("PCA9685 connected !");

os_timer_setfn(&timer1, timerCallback, &timer_flag);
os_timer_arm(&timer1, 20, true);
os_timer_arm(&timer1, 200, true);

stairs.setState(1);
stairs.setDirection(1);
}


void loop() {
if(millis() > 25000 && stairs.getState() == 1 && stairs.getDirection() == 1) stairs.setState(0);
if(millis() > 45000 && stairs.getDirection() == 1){
if(stairs.getState() == 0) {
delay(1000);
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");
}

+ 54
- 3
src/pwm.cpp View File

@@ -15,7 +15,7 @@ uint8_t Treppe::softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){

static uint8_t lastled = 255;
static float current_pwm = 0;
static float stepsize = 1.0;
static float stepsize = 0.5;
if(led != lastled){
pwmController.setChannelPWM(led, (uint16_t)startval);
lastled = led;
@@ -44,6 +44,7 @@ void Treppe::ledsequence(){
static uint8_t finish = 1;
static uint16_t status = 0;
uint16_t status_build = 0;

status_build |= direction << 8;
status_build |= state;
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(){
Serial.printf("differenz_pwm_pro_tick %f\n", differenz_pwm_pro_tick);
pwmController.resetDevices();
// Deactive PCA9685 due to LED Flickering
// Deactivate PCA9685_PhaseBalancer due to LED Flickering
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
// see also lib/PCA9685-Arduin/PCA9685.h:204
pwmController.init(PCA9685_PhaseBalancer_None);
@@ -102,9 +148,14 @@ void Treppe::setup(){
Serial.println("Hello from Treppe");
Serial.print("Treppe: initial parameters: stairs=");
Serial.println(stairs);
for(uint8_t i=0; i<stairs; i++) {
pwmController.setChannelPWM(i, idle_brightness);
}
}
void Treppe::task(){
ledsequence();
//ledsequence();
elelel();
}

uint16_t Treppe::setIdle(uint16_t _idle_brightness){

Loading…
Cancel
Save