ESP8266 Treppenlichtsteuerung mit OTA zum Firmware Upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

treppe.h 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include "FSMTreppe2/FSMTreppe2.h"
  3. #include "PCA9685.h"
  4. // #define LDRDEBUG // comment in to override LDR measurement
  5. #define LDR_HYS 5.0 // Hysteresis for switching off FSM [lux]
  6. #define SENSOR_OBEN 16
  7. #define SENSOR_UNTEN 12
  8. #define OE 14
  9. #define INT_TIME 20 // interrupt intervall [ms]
  10. class Treppe {
  11. private:
  12. const uint8_t stufen;
  13. uint16_t time_per_stair = 300; // dimmtime per stair [ms]
  14. uint16_t idle_brightness = 100;
  15. uint16_t idle_bright_internal = 0;
  16. uint16_t active_brightness = 500;
  17. uint16_t ldr_schwelle = 7; // activation value for FSM [lx]
  18. uint16_t start_pwm = 0;
  19. uint16_t ziel_pwm = 0;
  20. bool anim_beendet = true;
  21. uint8_t stufe = 0;
  22. uint16_t current_tick = 0;
  23. float current_pwm = 0.0;
  24. uint16_t ticks_pro_stufe = 0;
  25. float differenz_pwm_pro_tick = 0.0;
  26. bool dimm_stufe(uint8_t stufe);
  27. void anim_tick();
  28. void start_animation();
  29. void berechne_dimmer();
  30. // initialize with i2c-Address 0, use Wire Library
  31. PCA9685 pwmController;
  32. FSMTreppeModelClass FSMTreppe_Obj;
  33. FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
  34. FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
  35. void print_state_on_change();
  36. enum fsm_status_t {
  37. ST_INAKTIV_LDR =0,
  38. ST_RUHEZUSTAND =1,
  39. ST_AUFDIMMEN_HOCH =2,
  40. ST_WARTEN_HOCH =3,
  41. ST_ABDIMMEN_HOCH =4,
  42. ST_AUFDIMMEN_RUNTER =5,
  43. ST_WARTEN_RUNTER =6,
  44. ST_ABDIMMEN_RUNTER =7
  45. };
  46. enum fsm_laufrichtung_t {
  47. LR_RUNTER=0,
  48. LR_HOCH=1
  49. };
  50. enum fsm_dimmrichtung_t {
  51. DR_ABDIMMEN=0,
  52. DR_AUFDIMMEN=1
  53. };
  54. bool read_sensor(int sensor);
  55. float read_ldr();
  56. bool check_ldr();
  57. public:
  58. Treppe(uint8_t _stufen) : stufen(_stufen){
  59. FSMTreppe_Obj.initialize();
  60. berechne_dimmer();
  61. }
  62. ~Treppe() {
  63. FSMTreppe_Obj.terminate();
  64. }
  65. void setup();
  66. void task(); // call periodically
  67. // Parameter section
  68. void set_idle_pwm(uint16_t _idle_brightness);
  69. void activate_idle_pwm(bool active);
  70. void set_active_pwm(uint16_t _active_brightness);
  71. void set_time_per_stair(uint16_t _time_per_stair);
  72. };