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

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