ESP8266-RGB-Autocycle: Added autocycler for ESP8266 LED controller

This commit is contained in:
Nis Wechselberg 2015-10-16 11:05:46 +02:00
parent 5e4f266aa6
commit ce1ca4e38a

View file

@ -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);
}