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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #include "FSMTreppe/FSMTreppe.h"
  3. #include "PCA9685.h"
  4. #define SENSOR1 2
  5. #define SENSOR2 12
  6. #define OE 14
  7. #define INT_TIME 20 // interrupt intervall [ms]
  8. class Treppe {
  9. private:
  10. // initialize with i2c-Address 0, use Wire Library
  11. PCA9685 pwmController;
  12. FSMTreppeModelClass FSMTreppe_Obj;// Instance of model class
  13. uint8_t stairs;
  14. uint16_t time_per_stair = 300; // dimmtime per stair [ms]
  15. uint16_t idle_brightness = 100;
  16. uint16_t active_brightness = 2048;
  17. uint8_t direction = 0;
  18. uint8_t switch_direction = 0;
  19. uint8_t state = 0;
  20. uint8_t switch_state = 0;
  21. uint8_t finish = 1;
  22. // alternative
  23. uint32_t tick = 0;
  24. uint32_t stufe = 0;
  25. uint8_t an_aus = 0;
  26. uint32_t ticks_treppe = 0;
  27. uint32_t ticks_pro_stufe = 0;
  28. float differenz_pwm_pro_tick = 0.0;
  29. // alternative
  30. uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
  31. void ledsequence();
  32. void rampe();
  33. public:
  34. Treppe(uint8_t _stairs) : stairs(_stairs){
  35. FSMTreppe_Obj.initialize();
  36. ticks_pro_stufe = time_per_stair / 20; // [ms]
  37. ticks_treppe = ticks_pro_stufe * stairs;
  38. differenz_pwm_pro_tick = (float) (active_brightness - idle_brightness)
  39. / (float) ticks_pro_stufe;
  40. }
  41. ~Treppe() {
  42. FSMTreppe_Obj.terminate();
  43. }
  44. void setup();
  45. void task(); // call periodically
  46. // Parameter section
  47. uint16_t setIdle(uint16_t _idle_brightness);
  48. uint16_t setActive(uint16_t _active_brightness);
  49. uint16_t setTime(uint16_t _time_per_stair);
  50. void setTick(uint32_t _tick) {
  51. tick = _tick;
  52. Serial.printf("Treppe: Tick: %u!\n", tick);
  53. }
  54. uint32_t getTicks() {
  55. return ticks_treppe;
  56. }
  57. // Runtime Parameter section
  58. void setDirection(uint8_t _direction);
  59. void setState(uint8_t _state);
  60. void setAnAus(uint8_t _an_aus) {
  61. an_aus = _an_aus;
  62. }
  63. uint8_t getState() { return state;};
  64. uint8_t getFinished() { return finish;};
  65. uint8_t getDirection() {return direction;};
  66. };