Last active
March 11, 2023 15:20
-
-
Save elktros/ec3012afac66b7557f6088ae2fe17ae4 to your computer and use it in GitHub Desktop.
Code for ESP8266 PWM Tutorial. LED Fading using ESP8266 WiFi Module.
This file contains 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
#include <ESP8266WiFi.h> | |
#define ledPin 2 | |
int brightness = 0; | |
int fadeAmount = 1; | |
void setup() | |
{ | |
Serial.begin(115200); | |
pinMode(ledPin,OUTPUT); | |
} | |
void loop() | |
{ | |
Serial.println("10% Duty Cycle"); | |
analogWrite(ledPin,102); | |
delay(2000); | |
Serial.println("20% Duty Cycle"); | |
analogWrite(ledPin,205); | |
delay(2000); | |
Serial.println("50% Duty Cycle"); | |
analogWrite(ledPin,511); | |
delay(2000); | |
Serial.println("70% Duty Cycle"); | |
analogWrite(ledPin,714); | |
delay(2000); | |
Serial.println("100% Duty Cycle"); | |
analogWrite(ledPin,1023); | |
delay(2000); | |
Serial.println("LED Fadding begins....."); | |
while(1) | |
{ | |
analogWrite(ledPin, brightness); | |
brightness = brightness + fadeAmount; | |
if (brightness <= 0 || brightness >= 1023) | |
{ | |
fadeAmount = -fadeAmount; | |
} | |
delay(10); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment