Created
September 27, 2023 09:25
-
-
Save kakopappa/b34693c62c679437fa3a7465a242d7f2 to your computer and use it in GitHub Desktop.
Dimmable Switch with YYAC-3S. https://help.sinric.pro/pages/tutorials/tutorials/dimmable-switch/YYAC-3S.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int pwmPin = 16; // 16 corresponds to GPIO16 of ESP32 | |
| // setting PWM properties | |
| const int freq = 1000; // 1KHz | |
| const int ledChannel = 0; | |
| const int resolution = 8; | |
| void setup(){ | |
| ledcSetup(ledChannel, freq, resolution); | |
| ledcAttachPin(pwmPin, ledChannel); | |
| } | |
| void loop(){ | |
| /* dutyCycle between 0 to 115 does not seems to have an any effect on the bulb. */ | |
| // increase the brightness. | |
| for(int dutyCycle = 115; dutyCycle <= 255; dutyCycle++){ | |
| ledcWrite(ledChannel, dutyCycle); | |
| delay(15); | |
| } | |
| // decrease the brightness | |
| for(int dutyCycle = 255; dutyCycle >= 115; dutyCycle--){ | |
| ledcWrite(ledChannel, dutyCycle); | |
| delay(15); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment