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 1.6KB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "PCA9685.h"
  3. class Treppe {
  4. private:
  5. uint8_t stairs;
  6. uint16_t time_per_stair = 300; // dimmtime per stair [ms]
  7. uint16_t idle_brightness = 0;
  8. uint16_t active_brightness = 500;
  9. uint8_t direction = 0;
  10. uint8_t state = 0;
  11. uint8_t switch_state = 0;
  12. uint32_t tick = 0;
  13. uint32_t stufe = 0;
  14. uint32_t ticks_treppe = 0;
  15. uint32_t ticks_pro_stufe = 0;
  16. float differenz_pwm_pro_tick = 0.0;
  17. // initialize with i2c-Address 0, use Wire Library
  18. PCA9685 pwmController;
  19. uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
  20. void ledsequence();
  21. public:
  22. Treppe(uint8_t _stairs) : stairs(_stairs){
  23. ticks_pro_stufe = time_per_stair / 20; // [ms]
  24. ticks_treppe = ticks_pro_stufe * stairs;
  25. differenz_pwm_pro_tick = (float) (active_brightness - idle_brightness)
  26. / (float) ticks_pro_stufe;
  27. }
  28. void task(); // call periodically
  29. void setup();
  30. void task_2();
  31. // Parameter section
  32. uint16_t setIdle(uint16_t _idle_brightness);
  33. uint16_t setActive(uint16_t _active_brightness);
  34. uint16_t setTime(uint16_t _time_per_stair);
  35. void setTick(uint32_t _tick) {
  36. tick = _tick;
  37. Serial.printf("Treppe: Tick: %u!\n", tick);
  38. }
  39. uint32_t getTicks() {
  40. return ticks_treppe;
  41. }
  42. // Runtime Parameter section
  43. uint8_t setDirection(uint8_t _direction);
  44. uint8_t setState(uint8_t _state);
  45. uint8_t getState() { return state;};
  46. uint8_t getDirection() {return direction;};
  47. };