ESP8266_Treppenlicht/lib/treppe/treppe.h

76 lines
1.9 KiB
C
Raw Normal View History

2021-06-23 19:23:31 +00:00
#pragma once
#include "PCA9685.h"
2021-06-30 09:23:56 +00:00
#define SENSOR1 16
2021-06-25 17:23:02 +00:00
#define SENSOR2 12
2021-06-28 13:47:10 +00:00
#define OE 14
2021-06-25 17:23:02 +00:00
#define INT_TIME 20 // interrupt intervall [ms]
2021-06-23 19:23:31 +00:00
class Treppe {
2021-06-25 02:53:06 +00:00
private:
2021-06-23 19:23:31 +00:00
uint8_t stairs;
2021-06-25 16:35:16 +00:00
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
uint16_t idle_brightness = 0;
2021-06-30 14:09:46 +00:00
uint16_t active_brightness = 3000;
2021-06-23 19:23:31 +00:00
uint8_t direction = 0;
2021-06-25 17:23:02 +00:00
uint8_t switch_direction = 0;
2021-06-23 19:23:31 +00:00
uint8_t state = 0;
uint8_t switch_state = 0;
2021-06-25 17:23:02 +00:00
uint8_t finish = 1;
2021-06-23 19:23:31 +00:00
2021-06-25 19:10:07 +00:00
// alternative
2021-06-25 02:53:06 +00:00
uint32_t tick = 0;
uint32_t stufe = 0;
2021-06-25 19:10:07 +00:00
uint8_t an_aus = 0;
2021-06-25 02:53:06 +00:00
uint32_t ticks_treppe = 0;
uint32_t ticks_pro_stufe = 0;
float differenz_pwm_pro_tick = 0.0;
2021-06-25 19:10:07 +00:00
// alternative
2021-06-25 02:53:06 +00:00
// initialize with i2c-Address 0, use Wire Library
PCA9685 pwmController;
2021-06-23 19:23:31 +00:00
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
void ledsequence();
2021-06-25 19:10:07 +00:00
void rampe();
2021-06-23 19:23:31 +00:00
2021-06-25 02:53:06 +00:00
public:
Treppe(uint8_t _stairs) : stairs(_stairs){
ticks_pro_stufe = time_per_stair / 20; // [ms]
ticks_treppe = ticks_pro_stufe * stairs;
2021-06-25 16:35:16 +00:00
differenz_pwm_pro_tick = (float) (active_brightness - idle_brightness)
/ (float) ticks_pro_stufe;
2021-06-25 02:53:06 +00:00
}
2021-06-25 16:35:16 +00:00
2021-06-23 19:23:31 +00:00
void setup();
2021-06-25 19:10:07 +00:00
void task(); // call periodically
2021-06-23 19:23:31 +00:00
// Parameter section
uint16_t setIdle(uint16_t _idle_brightness);
uint16_t setActive(uint16_t _active_brightness);
uint16_t setTime(uint16_t _time_per_stair);
2021-06-25 16:35:16 +00:00
void setTick(uint32_t _tick) {
tick = _tick;
Serial.printf("Treppe: Tick: %u!\n", tick);
}
uint32_t getTicks() {
return ticks_treppe;
}
2021-06-23 19:23:31 +00:00
// Runtime Parameter section
2021-06-25 19:10:07 +00:00
void setDirection(uint8_t _direction);
void setState(uint8_t _state);
void setAnAus(uint8_t _an_aus) {
an_aus = _an_aus;
}
2021-06-23 19:23:31 +00:00
uint8_t getState() { return state;};
2021-06-25 19:10:07 +00:00
uint8_t getFinished() { return finish;};
2021-06-23 19:23:31 +00:00
uint8_t getDirection() {return direction;};
};