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

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