Created
January 23, 2020 19:45
-
-
Save futureshocked/e457e0ebc451ca6c640f72461cc3dd48 to your computer and use it in GitHub Desktop.
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 byte led_gpio = 32; // the PWM pin the LED is attached to | |
| int brightness = 0; // how bright the LED is | |
| int fadeAmount = 5; // how many points to fade the LED by | |
| void setup() { | |
| ledcAttachPin(led_gpio, 0); // assign a led pins to a channel | |
| // Initialize channels | |
| // channels 0-15, resolution 1-16 bits, freq limits depend on resolution | |
| // ledcSetup(uint8_t channel, uint32_t freq, uint8_t resolution_bits); | |
| ledcSetup(0, 4000, 8); // 12 kHz PWM, 8-bit resolution | |
| } | |
| // the loop routine runs over and over again forever: | |
| void loop() { | |
| ledcWrite(0, brightness); // set the brightness of the LED | |
| // change the brightness for next time through the loop: | |
| brightness = brightness + fadeAmount; | |
| // reverse the direction of the fading at the ends of the fade: | |
| if (brightness <= 0 || brightness >= 255) { | |
| fadeAmount = -fadeAmount; | |
| } | |
| // wait for 30 milliseconds to see the dimming effect | |
| delay(30); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment