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

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 1 // 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_pwm = 100;
  15. uint16_t idle_pwm_internal = 0;
  16. uint16_t active_pwm = 700;
  17. uint16_t ldr_schwelle = 2; // 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. // initialize with i2c-Address 0, use Wire Library
  27. PCA9685 pwmController;
  28. FSMTreppeModelClass FSMTreppe_Obj;
  29. FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
  30. FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
  31. enum fsm_status_t {
  32. ST_INAKTIV_LDR =0,
  33. ST_RUHEZUSTAND =1,
  34. ST_AUFDIMMEN_HOCH =2,
  35. ST_WARTEN_HOCH =3,
  36. ST_ABDIMMEN_HOCH =4,
  37. ST_AUFDIMMEN_RUNTER =5,
  38. ST_WARTEN_RUNTER =6,
  39. ST_ABDIMMEN_RUNTER =7
  40. };
  41. enum fsm_laufrichtung_t {
  42. LR_RUNTER=0,
  43. LR_HOCH=1
  44. };
  45. enum fsm_dimmrichtung_t {
  46. DR_ABDIMMEN=0,
  47. DR_AUFDIMMEN=1
  48. };
  49. /* DIMM */
  50. bool dimm_stufe(uint8_t stufe);
  51. bool dimm_treppe();
  52. void anim_tick();
  53. void start_animation();
  54. void berechne_dimmer();
  55. void print_state_on_change();
  56. /* LDR */
  57. bool read_sensor(int sensor);
  58. float read_ldr();
  59. bool check_ldr();
  60. public:
  61. Treppe(uint8_t _stufen) : stufen(_stufen){
  62. FSMTreppe_Obj.initialize();
  63. berechne_dimmer();
  64. }
  65. ~Treppe() {
  66. FSMTreppe_Obj.terminate();
  67. }
  68. void setup();
  69. void task(); // call periodically
  70. // Parameter section
  71. void set_idle_prozent(int prozent);
  72. void set_idle_pwm(uint16_t _idle_pwm);
  73. void activate_idle_pwm(bool active);
  74. void set_active_pwm(uint16_t _active_pwm);
  75. void set_time_per_stair(uint16_t _time_per_stair);
  76. };