Skip to content

Instantly share code, notes, and snippets.

@ironpinguin
Created June 2, 2017 14:28
Show Gist options
  • Save ironpinguin/53343aebc2e6bdfeaa571d99e9385973 to your computer and use it in GitHub Desktop.
Save ironpinguin/53343aebc2e6bdfeaa571d99e9385973 to your computer and use it in GitHub Desktop.
/*
ESP8266 Blink by Simon Peter
Blink the blue LED on the ESP-01 module
This example code is in the public domain
The blue LED on the ESP-01 module is connected to GPIO1
(which is also the TXD pin; so we cannot use Serial.print() at the same time)
Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/
const int RLED = 14;
const int GLED = 4;
const int BLED = 5;
int brightnessr = 0; // how bright the LED is
int brightnessg = 100; // how bright the LED is
int brightnessb = 200; // how bright the LED is
int fadeAmountr = 5; // how many points to fade the LED by
int fadeAmountg = 5; // how many points to fade the LED by
int fadeAmountb = 5; // how many points to fade the LED by
void setup() {
pinMode(RLED, brightnessr); // Initialize the LED_BUILTIN pin as an output
pinMode(GLED, brightnessg); // Initialize the LED_BUILTIN pin as an output
pinMode(BLED, brightnessb); // Initialize the LED_BUILTIN pin as an output
}
// the loop function runs over and over again forever
void loop() {
analogWrite(RLED, brightnessr); // Turn the LED on (Note that LOW is the voltage level
analogWrite(GLED, brightnessg); // Turn the LED on (Note that LOW is the voltage level
analogWrite(BLED, brightnessb); // Turn the LED on (Note that LOW is the voltage level
brightnessr = brightnessr + fadeAmountr;
brightnessg = brightnessg + fadeAmountg;
brightnessb = brightnessb + fadeAmountb;
// reverse the direction of the fading at the ends of the fade:
if (brightnessr <= 0 || brightnessr >= 255) {
fadeAmountr = -fadeAmountr;
}
// reverse the direction of the fading at the ends of the fade:
if (brightnessg <= 0 || brightnessg >= 255) {
fadeAmountg = -fadeAmountg;
}
// reverse the direction of the fading at the ends of the fade:
if (brightnessb <= 0 || brightnessb >= 255) {
fadeAmountb = -fadeAmountb;
}
delay(30); // Wait for a second
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment