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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include "FSMTreppe2/FSMTreppe2.h"
  3. #include "PCA9685.h"
  4. #define SENSOR_OBEN 2
  5. #define SENSOR_UNTEN 12
  6. #define OE 14
  7. #define INT_TIME 20 // interrupt intervall [ms]
  8. class Treppe {
  9. private:
  10. const uint8_t stufen;
  11. uint16_t time_per_stair = 300; // dimmtime per stair [ms]
  12. uint16_t idle_brightness = 0;
  13. uint16_t active_brightness = 500;
  14. uint16_t start_pwm = 0;
  15. uint16_t ziel_pwm = 0;
  16. bool anim_beendet = true;
  17. uint8_t stufe = 0;
  18. uint16_t current_tick = 0;
  19. float current_pwm = 0.0;
  20. uint16_t ticks_pro_stufe = 0;
  21. float differenz_pwm_pro_tick = 0.0;
  22. bool dimm_stufe(uint8_t stufe);
  23. void anim_tick();
  24. void start_animation();
  25. void berechne_dimmer();
  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. void print_state_on_change();
  32. enum fsm_status_t {
  33. ST_INAKTIV_LDR =0,
  34. ST_RUHEZUSTAND =1,
  35. ST_AUFDIMMEN_HOCH =2,
  36. ST_WARTEN_HOCH =3,
  37. ST_ABDIMMEN_HOCH =4,
  38. ST_AUFDIMMEN_RUNTER =5,
  39. ST_WARTEN_RUNTER =6,
  40. ST_ABDIMMEN_RUNTER =7
  41. };
  42. enum fsm_laufrichtung_t {
  43. LR_RUNTER=0,
  44. LR_HOCH=1
  45. };
  46. enum fsm_dimmrichtung_t {
  47. DR_ABDIMMEN=0,
  48. DR_AUFDIMMEN=1
  49. };
  50. bool read_sensor(int sensor) {
  51. int pegel = digitalRead(sensor);
  52. return static_cast<bool>(pegel);
  53. }
  54. public:
  55. Treppe(uint8_t _stufen) : stufen(_stufen){
  56. FSMTreppe_Obj.initialize();
  57. berechne_dimmer();
  58. }
  59. ~Treppe() {
  60. FSMTreppe_Obj.terminate();
  61. }
  62. void setup();
  63. void task(); // call periodically
  64. // Parameter section
  65. void set_idle_pwm(uint16_t _idle_brightness);
  66. void set_active_pwm(uint16_t _active_brightness);
  67. void set_time_per_stair(uint16_t _time_per_stair);
  68. };