Adafruit Neopixel Button Cycler Sample Adapted....
Posted: Mon Nov 16, 2015 3:04 pm
This will use the Flash button to select the animation from the default Sample Sketch but also host an AP with a web page to select from some of the animations pre loaded with the library.
This includes some other web pages in the sketch I have left in to be reused...along with lots of extra declarations.....still loads of resources so re-use.....
This includes some other web pages in the sketch I have left in to be reused...along with lots of extra declarations.....still loads of resources so re-use.....
Code: Select all
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 150KB free Sketch Space 31 KB free Memory and Untouched SPIFFS........
//
//
// This is a demonstration on how to use an input device & webpage to trigger changes on your neo pixels.
// You should wire a momentary push button to connect from ground to a digital IO pin(use the flash button).
// When you press the button it will change to a new pixel animation. Note that you need to press the
// button once or trigger from webpage to start the first animation!
___/'¬_ /\
{_-_ ^ \_______//
/ \
\ _ _____ /
|| || |||
|| || |||
_____
</\|/\>
_-_-_-_ *|* _-_-_-_
-_-_-_-_-\@/-_-_-_-_-
_____________________________
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
#include <ESP8266WiFi.h>
#include "FS.h"
#include <Adafruit_NeoPixel.h>
const char* host = "EM-Pixels";
IPAddress apIP(192, 168, 4, 1);
WiFiServer server(80);
WiFiClient client;
extern "C"
{
#include "user_interface.h"
}
ADC_MODE(ADC_VCC); // !!*!*!*!*! DO NOT USE THIS IF LDR FITTED !*!*!*!*!*!!
// Use this instead of ESP.getVcc() for modules with LDR Fitted, Alter Display Text from Volts!!!
// This is the Start of the LDR Sensor Measurement Percent/10 Saturation of LDR
// Keep the Scale relavant for Line Graph or select Different Axis.....(When Used)
/*
delay(25);
int pfVcC = 10-(constrain(map((analogRead(A0)), 40, 900, 1, 10), 1, 10)) ;
delay(25);
//
// This is the End of the LDR Sensor Measurement
//
*/
///////////////////////////////////////////////////////////////////////////////
int wloop=5;
char tDigit;
String TiMeS,TMnow,MyNtP; // The current TimeStamp from Google....
int tIMeh,tIMem,tIMes,newt,newt1,inChar,SCsa,MNsa,HRsa;
boolean got_text = false; //Print the Text to LCD if true......
int hr,mn,st,st1; // Uptime Duration Counter......
String DsTable; //Discarded parts if the Strings......
String tmtxt1,tmtxt2,DisTeXt0,DisTeXt1; //Strings from the Web....
String theDate,theDate1,duration1,theDateTr; // The current TimeStamp Date from Google....
unsigned long ulMeasCount=0; // values already measured
unsigned long ulMeasDelta_ms; // distance to next meas time
unsigned long ulNextMeas_ms; // next meas time
unsigned long ulReqcount; // how often has a valid page been requested
unsigned long ulReconncount; // how often did we connect to WiFi
////////////////////////////////////////////////////////////////////////////////
// The Flash Button fitted to GPIO 0 on most development modules can be used.
#define BUTTON_PIN 0 // Digital IO pin connected to the button. This will be
// driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily. On a high -> low
// transition the button press logic will execute.
#define PIXEL_PIN 12 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 40
// Parameter 1 = number of pixels in strip, neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH; // Switch
int showType = 0;
bool animate = false; // Web Button
void setup() {
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("Pixels http://192.168.4.1"); // Create WiFi network
WiFi.begin();
server.begin();
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
///////////////////////////////1
void wsysreset()
{
//Perform challenge to user before getting here to reboot !!!
//Make an attempt to send mail or other backup of log files then reboot
ESP.restart();
}
//////////////////////////
// create HTTP 1.1 header
//////////////////////////
String MakeHTTPHeader(unsigned long ulLength)
{
String sHeader;
sHeader = F("HTTP/1.1 200 OK\r\nContent-Length: ");
sHeader += ulLength;
sHeader += F("\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n");
return(sHeader);
}
////////////////////
// make html footer
////////////////////
String MakeHTTPFooter()
{
String sResponse;
sResponse = F(" ");
sResponse += F("<BR><BR><FONT SIZE=-1>ESP8266 With 40 WS2812B LED's<BR><FONT SIZE=-2>Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015</body></html>");
return(sResponse);
}
//////////////////////////////////1
void loop() {
// Get current button state.
bool newState = digitalRead(BUTTON_PIN);
// Check if state changed from high to low (button press).
if ((newState == LOW && oldState == HIGH) || (animate == true)) {
// Short delay to debounce button.
delay(2);
// Check if button is still low after debounce.
newState = digitalRead(BUTTON_PIN);
if ((newState == LOW) || (animate == true)) {
if (newState == LOW){
showType++;
if (showType > 9){
showType=0;
}
//theaterChase(strip.Color( 0, 0, 127), 50); // Blue
startShow(showType);
}
if (animate == true){
startShow(showType);
}
}
}
// Set the last button state to the old state.
oldState = newState;
////////////////////////////////////////////////////////////////////////2
///////////////////////////////////
// Check if a client has connected
///////////////////////////////////
WiFiClient client = server.available();
if (!client)
{
return;
}
// Wait until the client sends some data
unsigned long ultimeout = millis()+250;
while(!client.available() && (millis()<ultimeout) )
{
delay(1);
}
if(millis()>ultimeout)
{
return;
}
/////////////////////////////////////
// Read the first line of the request
/////////////////////////////////////
String sRequest = client.readStringUntil('\r');
client.flush();
// stop client, if request is empty
if(sRequest=="")
{
client.stop();
return;
}
// get path; end of path is either space or ?
// Syntax is e.g. GET /?show=1234 HTTP/1.1
String sPath="",sParam="", sCmd="";
String sGetstart="GET ";
int iStart,iEndSpace,iEndQuest;
iStart = sRequest.indexOf(sGetstart);
if (iStart>=0)
{
iStart+=+sGetstart.length();
iEndSpace = sRequest.indexOf(" ",iStart);
iEndQuest = sRequest.indexOf("?",iStart);
// are there parameters?
if(iEndSpace>0)
{
if(iEndQuest>0)
{
// there are parameters
sPath = sRequest.substring(iStart,iEndQuest);
sParam = sRequest.substring(iEndQuest,iEndSpace);
}
else
{
// NO parameters
sPath = sRequest.substring(iStart,iEndSpace);
}
}
}
///////////////////////////
// format the html response
///////////////////////////
String sResponse,sResponse2,sHeader;
if (sPath.startsWith("/pixel_inputs&LED"))
{
//
if (sPath.startsWith("/pixel_inputs&LED3=0")) {
showType=0;
if (TMnow=="false"){
animate = true;
}
TMnow="true";
}
else if (sPath.startsWith("/pixel_inputs&LED3=1")) {
showType=1;
animate = true;
}
else if (sPath.startsWith("/pixel_inputs&LED3=2")) {
showType=2;
animate = true;
}
else if (sPath.startsWith("/pixel_inputs&LED3=3")) {
showType=3;
animate = true;
}
else if (sPath.startsWith("/pixel_inputs&LED3=4")) {
showType=4;
animate = true;
}
else if (sPath.startsWith("/pixel_inputs&LED3=5")) {
showType=5;
animate = true;
}
else if (sPath.startsWith("/pixel_inputs&LED3=6")) {
showType=6;
animate = true;
}
else if (sPath.startsWith("/pixel_inputs&LED3=7")) {
showType=7;
animate = true;
}
else if (sPath.startsWith("/pixel_inputs&LED3=8")) {
showType=8;
animate = true;
}
else if (sPath.startsWith("/pixel_inputs&LED3=9")) {
showType=9;
animate = true;
}
}
/////////////////////////////////////////
// format the html page for Pixel Input /
/////////////////////////////////////////
if(sPath=="/")
{
ulReqcount++;
sResponse = F("<html>\n<head>\n<title>Webpage NeoPixel Controller</title>\n</head>\n");
sResponse += F("\n<script>\nfunction GetButton1()\n{\nnocache = \"&nocache=\" + Math.random() * 1000000;\nvar request = new XMLHttpRequest();\nrequest.open(\"GET\", \"pixel_inputs&LED3=0\" + nocache, true);\nrequest.send(null);\n}\nfunction GetButton2()\n{\nnocache = \"&nocache=\" + Math.random() * 1000000;\nvar request = new XMLHttpRequest();\nrequest.open(\"GET\", \"pixel_inputs&LED3=1\" + nocache, true);\nrequest.send(null);\n}\n");
sResponse += F("\nfunction GetButton3()\n{\n\nnocache = \"&nocache=\" + Math.random() * 1000000;\nvar request = new XMLHttpRequest();\nrequest.open(\"GET\", \"pixel_inputs&LED3=2\" + nocache, true);\nrequest.send(null);\n}\nfunction GetButton4()\n{\nnocache = \"&nocache=\" + Math.random() * 1000000;\nvar request = new XMLHttpRequest();\nrequest.open(\"GET\", \"pixel_inputs&LED3=3\" + nocache, true);\nrequest.send(null);\n}\nfunction GetButton5()\n");
sResponse += F("{\nnocache = \"&nocache=\" + Math.random() * 1000000;\nvar request = new XMLHttpRequest();\nrequest.open(\"GET\", \"pixel_inputs&LED3=4\" + nocache, true);\nrequest.send(null);\n}\nfunction GetButton6()\n{\nnocache = \"&nocache=\" + Math.random() * 1000000;\nvar request = new XMLHttpRequest();\nrequest.open(\"GET\", \"pixel_inputs&LED3=5\" + nocache, true);\nrequest.send(null);\n}\n");
sResponse += F("\nfunction GetButton7()\n{\nnocache = \"&nocache=\" + Math.random() * 1000000;\nvar request = new XMLHttpRequest();\nrequest.open(\"GET\", \"pixel_inputs&LED3=6\" + nocache, true);\nrequest.send(null);\n}\nfunction GetButton8()\n{\nnocache = \"&nocache=\" + Math.random() * 1000000;\nvar request = new XMLHttpRequest();\nrequest.open(\"GET\", \"pixel_inputs&LED3=7\" + nocache, true);\nrequest.send(null);\n}\nfunction GetButton9()\n{\nnocache = \"&nocache=\" + Math.random() * 1000000;\nvar request = new XMLHttpRequest();\nrequest.open(\"GET\", \"pixel_inputs&LED3=8\" + nocache, true);\nrequest.send(null);\n}\n");
sResponse += F("\nfunction GetButton10()\n{\nnocache = \"&nocache=\" + Math.random() * 1000000;\nvar request = new XMLHttpRequest();\nrequest.open(\"GET\", \"pixel_inputs&LED3=9\" + nocache, true);\nrequest.send(null);\n}\n</script>\n<body>\n<h1>NeoPixel Controller<BR>_________________</h1>\n<BR><BR><a href=\"/diag\">Diagnostics Information Page</a><BR>\n<body onload=\"GetESP8266IO()\">\n<h1><FONT SIZE=-1>Choose Animation of LED's</h1>\n<form id=\"txt_form\" name=\"frmText\">\n");
sResponse += F("\n<button type=\"button\" id=\"LED3\" onclick=\"GetButton1()\">Pixels Set to OFF</button><br /><br />\n<button type=\"button\" id=\"LED3\" onclick=\"GetButton2()\">Pixels Red</button><br /><br />\n<button type=\"button\" id=\"LED3\" onclick=\"GetButton3()\">Pixels Green</button><br /><br />\n<button type=\"button\" id=\"LED3\" onclick=\"GetButton4()\">Pixels Blue</button><br /><br />\n<button type=\"button\" id=\"LED3\" onclick=\"GetButton5()\">Pixel Animation 4</button><br /><br />\n<button type=\"button\" id=\"LED3\" onclick=\"GetButton6()\">Pixel Animation 5</button><br />");
sResponse2 = F("<br />\n<button type=\"button\" id=\"LED3\" onclick=\"GetButton7()\">Police Light</button><br /><br />\n<button type=\"button\" id=\"LED3\" onclick=\"GetButton8()\">Pixel Animation 7</button><br /><br />\n<button type=\"button\" id=\"LED3\" onclick=\"GetButton9()\">Pixel Animation 8</button><br /><br />\n<button type=\"button\" id=\"LED3\" onclick=\"GetButton10()\">Pixel Animation 9</button><br /><br />\n</form>\n<br />\n");
sResponse2 += F("\n<font color=\"#000000\"><body bgcolor=\"#a0dFfe\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\"><BR>Animated Neopixels ANY TYPE !<BR>\n</div>\n<div style=\"clear:both;\"></div><p>\n");
sResponse2 += MakeHTTPFooter().c_str();
// Send the response to the client
client.print(MakeHTTPHeader(sResponse.length()+sResponse2.length()).c_str());
client.print(sResponse);
client.print(sResponse2);
}
else if(sPath=="/yfireset") // When Google time is used this will Sync the C
{
ulReqcount++;
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.print("<html><head><title>Webpage NeoPixel Controller</title></head><body>");
client.print("<font color=\"#000000\"><body bgcolor=\"#a0dFfe\">");
client.print("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">");
client.print("<h1>Webpage NeoPixel Controller<BR>WiFi Reset Page </h1><BR><a href=\"/graphic2\">Pressure Graph Page</a><BR><a href=\"/pressure\">Pressure Gauge Page</a>");
client.print("<BR><a href=\"/monitor\">Sensor Gauges Page</a><BR><a href=\"/graphic\">Sensor Graph Page</a><BR><a href=\"/table\">Sensor Datalog Page</a><BR><BR><BR><BR>Restarted WiFiConnections = ");
client.print(ulReconncount);
client.print("<BR><FONT SIZE=-2>environmental.monitor.log@gmail.com<BR><FONT SIZE=-2>ESP8266 With DHT11 & BMP180 Sensors<BR>");
client.print("<FONT SIZE=-2>Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015<BR>");
client.println("<IMG SRC=\"https://raw.githubusercontent.com/genguskahn/ESP8266-For-DUMMIES/master/SoC/DimmerDocs/organicw.gif\" WIDTH=\"250\" HEIGHT=\"151\" BORDER=\"1\"></body></html>");
//WiFiStart();
}
else if(sPath=="/diag")
{
float servolt1 = ESP.getVcc();
long int spdcount = ESP.getCycleCount();
delay(1);
long int spdcount1 = ESP.getCycleCount();
long int speedcnt = spdcount1-spdcount;
FlashMode_t ideMode = ESP.getFlashChipMode();
ulReqcount++;
String duration1 = " ";
int hr,mn,st;
st = millis() / 1000;
mn = st / 60;
hr = st / 3600;
st = st - mn * 60;
mn = mn - hr * 60;
if (hr<10) {duration1 += ("0");}
duration1 += (hr);
duration1 += (":");
if (mn<10) {duration1 += ("0");}
duration1 += (mn);
duration1 += (":");
if (st<10) {duration1 += ("0");}
duration1 += (st);
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.print("<html><head><title>Webpage NeoPixel Controller</title></head><body>");
client.print("<font color=\"#000000\"><body bgcolor=\"#a0dFfe\">");
client.print("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">");
client.print("<h1>Neopixel Control<BR>SDK Diagnostic Information</h1>");
client.print("<BR><a href=\"/\">Pixel Control Page</a><BR>");
String diagdat="";
// diagdat+=ulReconncount;
diagdat+="<BR> Web Page Requests = ";
diagdat+=ulReqcount;
diagdat+="<BR> WiFi AP Hostname = ";
diagdat+=host;
diagdat+="<BR> Free RAM = ";
client.print(diagdat);
client.print((uint32_t)system_get_free_heap_size()/1024);
// diagdat=" KBytes<BR> Logged Sample Count = ";
// diagdat+=ulMeasCount;
diagdat=" KBytes<BR> SDK Version = ";
diagdat+=ESP.getSdkVersion();
diagdat+="<BR> Boot Version = ";
diagdat+=ESP.getBootVersion();
diagdat+="<BR> Free Sketch Space = ";
diagdat+=ESP.getFreeSketchSpace()/1024;
diagdat+=" KBytes<BR> Sketch Size = ";
diagdat+=ESP.getSketchSize()/1024;
diagdat+=" KBytes<BR>";
client.print(diagdat);
client.printf(" Flash Chip id = %08X\n", ESP.getFlashChipId());
client.print("<BR>");
client.printf(" Flash Chip Mode = %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));
diagdat="<BR> Flash Size By ID = ";
diagdat+=ESP.getFlashChipRealSize()/1024;
diagdat+=" KBytes<BR> Flash Size (IDE) = ";
diagdat+=ESP.getFlashChipSize()/1024;
diagdat+=" KBytes<BR> Flash Speed = ";
diagdat+=ESP.getFlashChipSpeed()/1000000;
diagdat+=" MHz<BR> ESP8266 CPU Speed = ";
diagdat+=ESP.getCpuFreqMHz();
diagdat+=" MHz<BR>";
client.print(diagdat);
client.printf(" ESP8266 Chip id = %08X\n", ESP.getChipId());
diagdat="<BR> System Instruction Cycles Per Second = ";
diagdat+=speedcnt*1000;
diagdat+="<BR> Last System Restart Reason = ";
diagdat+=ESP.getResetInfo();
diagdat+="<BR> System VCC = ";
diagdat+=servolt1/1000, 3;
diagdat+=" V <BR> Datalog File Size in Bytes = N/A";
//diagdat+=Dfsize;
diagdat+="<BR> System Uptime =";
diagdat+=duration1;
client.print(diagdat);
client.print("<BR><FONT SIZE=-2>environmental.monitor.log@gmail.com<BR><FONT SIZE=-2>ESP8266 With 40 WS2812B 5050 LED's<BR><FONT SIZE=-2>Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015<BR>");
client.println("<IMG SRC=\"https://raw.githubusercontent.com/genguskahn/ESP8266-For-DUMMIES/master/SoC/DimmerDocs/organicw.gif\" WIDTH=\"250\" HEIGHT=\"151\" BORDER=\"1\"></body></html>");
diagdat = "";
duration1 = "";
}
else if(sPath=="/srestart")
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.print("<html><head><title>Webpage NeoPixel Controller</title></head><body>");
client.print("<font color=\"#000000\"><body bgcolor=\"#a0dFfe\">");
client.print("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">");
client.print("<h1>Environment Monitor<BR>Please wait 10 Seconds......<BR><FONT SIZE=+2>System Reset Page !!!! </h1><BR><a href=\"/graphic2\">Pressure Graph Page</a><BR><a href=\"/pressure\">Pressure Gauge Page</a>");
client.print("<BR><a href=\"/monitor\">Sensor Gauges Page</a><BR><a href=\"/graphic\">Sensor Graph Page</a><BR><a href=\"/table\">Sensor Datalog Page</a><BR><a href=\"/diag\">Diagnostics Information Page</a><BR><a href=\"/\">Monitor LCD Text Input Page</a><BR><BR><BR><BR>Restarted WiFiConnections = ");
client.print(ulReconncount);
client.print("<BR><BR><BR><FONT SIZE=-2>environmental.monitor.log@gmail.com<BR><FONT SIZE=-2>ESP8266 With DHT11 & BMP180 Sensors<BR>");
client.print("<FONT SIZE=-2>Compiled Using ver. 1.6.5-1160-gef26c5f, built on Sep 30, 2015<BR>");
client.println("<IMG SRC=\"https://raw.githubusercontent.com/genguskahn/ESP8266-For-DUMMIES/master/SoC/DimmerDocs/organicw.gif\" WIDTH=\"250\" HEIGHT=\"151\" BORDER=\"1\"></body></html>");
client.stop();
wsysreset();
}
else
////////////////////////////
// 404 for non-matching path
////////////////////////////
{
sResponse="<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server, What did you sk for?.</p></body></html>";
ulReqcount++;
sHeader = F("HTTP/1.1 404 Not found\r\nContent-Length: ");
sHeader += sResponse.length();
sHeader += F("\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n");
// Send the response to the client
client.print(sHeader);
client.print(sResponse);
}
// and stop the client
client.stop();
////////////////////////////////////////////////////////////////////////2
}
void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(0, 0, 0), 50); // Black/off
animate = false;
break;
case 1: colorWipe(strip.Color(255, 0, 0), 50); // Red
break;
case 2: colorWipe(strip.Color(0, 255, 0), 50); // Green
break;
case 3: colorWipe(strip.Color(0, 0, 255), 50); // Blue
break;
case 4: theaterChase(strip.Color(127, 127, 127), 50); // White
break;
case 5: theaterChase(strip.Color(127, 0, 0), 50); // Red
break;
case 6: theaterChase(strip.Color( 0, 0, 127), 50); // Blue
break;
case 7: rainbow(20);
break;
case 8: rainbowCycle(20);
break;
case 9: theaterChaseRainbow(50);
break;
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}