From ce1ca4e38abbb0f71f210b4d30616b8d41a5459c Mon Sep 17 00:00:00 2001 From: Nis Wechselberg Date: Fri, 16 Oct 2015 11:05:46 +0200 Subject: [PATCH] ESP8266-RGB-Autocycle: Added autocycler for ESP8266 LED controller --- .../ESP8266-RGB-Autocycle.ino | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ESP8266-RGB-Autocycle/ESP8266-RGB-Autocycle.ino diff --git a/ESP8266-RGB-Autocycle/ESP8266-RGB-Autocycle.ino b/ESP8266-RGB-Autocycle/ESP8266-RGB-Autocycle.ino new file mode 100644 index 0000000..aeaaa75 --- /dev/null +++ b/ESP8266-RGB-Autocycle/ESP8266-RGB-Autocycle.ino @@ -0,0 +1,70 @@ +/******************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2015 Nis Wechselberg + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ********************************************************************************/ + +/******************************************************************************** + * ESP8266-RGB-Autocycle + * Cycles an RGB LED Ribbon through all possible colors. + ********************************************************************************/ + +// Configuration +const int redPin = 12; +const int greenPin = 13; +const int bluePin = 14; + +void setup() { + // Start off with the LED off. + setColourRgb(0,0,0); +} + +void loop() { + // Store pwm value for each color channel + unsigned int rgbColour[3]; + + // Start off with red + rgbColour[0] = 1023; + rgbColour[1] = 0; + rgbColour[2] = 0; + + // Choose the colours to increment and decrement. + for (int decColour = 0; decColour < 3; decColour += 1) { + int incColour = decColour == 2 ? 0 : decColour + 1; + + // cross-fade the two colours. + for(int i = 0; i < 1023; i += 1) { + rgbColour[decColour] -= 1; + rgbColour[incColour] += 1; + + setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]); + delay(5); + } + } +} + +// Helper function to set the RGB value +void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) { + analogWrite(redPin, red); + analogWrite(greenPin, green); + analogWrite(bluePin, blue); + } +