Last active
August 23, 2017 18:37
-
-
Save cjdell/b4870b3c573047ea22807f05155f5367 to your computer and use it in GitHub Desktop.
Makerspace
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 <NeoPixelBus.h> | |
#include <IRremoteESP8266.h> | |
#include <IRrecv.h> | |
#include <IRutils.h> | |
const uint16_t PixelCount = 163; // this example assumes 4 pixels, making it smaller will cause a failure | |
const uint8_t RemotePin = 14; // make sure to set this to the correct pin, ignored for Esp8266 | |
NeoPixelBus<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod> strip(PixelCount, 2); | |
IRrecv remote(RemotePin); | |
RgbColor black(0); | |
void setup() | |
{ | |
Serial.begin(115200); | |
while (!Serial); // wait for serial attach | |
Serial.println(); | |
Serial.println("Initializing..."); | |
Serial.flush(); | |
remote.enableIRIn(); | |
// this resets all the neopixels to an off state | |
strip.Begin(); | |
strip.Show(); | |
Serial.println(); | |
Serial.println("Running..."); | |
} | |
int position = 0; | |
int interval = 50; | |
bool enabled = true; | |
decode_results results; | |
void loop() | |
{ | |
if (remote.decode(&results)) { | |
remote.resume(); | |
if (results.value == 0xFFE01F) { | |
interval++; | |
} | |
if (results.value == 0xFFA857) { | |
interval--; | |
} | |
if (results.value == 0xFFC23D) { | |
enabled = !enabled; | |
} | |
} | |
if (!enabled) { | |
strip.ClearTo(black); | |
strip.Show(); | |
return; | |
} | |
for (int led = 0; led < PixelCount; led++) { | |
float hue = (float)((position + led) % PixelCount) / (float)PixelCount; | |
HslColor color = HslColor(hue, 1.0f, 0.5f); | |
strip.SetPixelColor(led, color); | |
} | |
strip.Show(); | |
delay(interval); | |
position++; | |
strip.ClearTo(black); | |
} |
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
// NeoPixelTest | |
// This example will cycle between showing four pixels as Red, Green, Blue, White | |
// and then showing those pixels as Black. | |
// | |
// Included but commented out are examples of configuring a NeoPixelBus for | |
// different color order including an extra white channel, different data speeds, and | |
// for Esp8266 different methods to send the data. | |
// NOTE: You will need to make sure to pick the one for your platform | |
// | |
// | |
// There is serial output of the current state so you can confirm and follow along | |
// | |
#include <NeoPixelBus.h> | |
const uint16_t PixelCount = 283; // this example assumes 4 pixels, making it smaller will cause a failure | |
const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266 | |
#define colorSaturation 128 | |
// three element pixels, in different order and speeds | |
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin); | |
//NeoPixelBus<NeoRgbFeature, Neo400KbpsMethod> strip(PixelCount, PixelPin); | |
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use. | |
// There are other Esp8266 alternative methods that provide more pin options, but also have | |
// other side effects. | |
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount); | |
// | |
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead | |
// You can also use one of these for Esp8266, | |
// each having their own restrictions | |
// | |
// These two are the same as above as the DMA method is the default | |
// NOTE: These will ignore the PIN and use GPI03 pin | |
NeoPixelBus<NeoRgbFeature, NeoEsp8266Dma800KbpsMethod> strip(PixelCount, PixelPin); | |
//NeoPixelBus<NeoRgbFeature, NeoEsp8266Dma400KbpsMethod> strip(PixelCount, PixelPin); | |
// Uart method is good for the Esp-01 or other pin restricted modules | |
// NOTE: These will ignore the PIN and use GPI02 pin | |
//NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(PixelCount, PixelPin); | |
//NeoPixelBus<NeoRgbFeature, NeoEsp8266Uart400KbpsMethod> strip(PixelCount, PixelPin); | |
// The bitbang method is really only good if you are not using WiFi features of the ESP | |
// It works with all but pin 16 | |
//NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> strip(PixelCount, PixelPin); | |
//NeoPixelBus<NeoRgbFeature, NeoEsp8266BitBang400KbpsMethod> strip(PixelCount, PixelPin); | |
// four element pixels, RGBW | |
//NeoPixelBus<NeoRgbwFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin); | |
RgbColor red(colorSaturation, 0, 0); | |
RgbColor green(0, colorSaturation, 0); | |
RgbColor blue(0, 0, colorSaturation); | |
RgbColor white(colorSaturation); | |
RgbColor black(0); | |
HslColor hslRed(red); | |
HslColor hslGreen(green); | |
HslColor hslBlue(blue); | |
HslColor hslWhite(white); | |
HslColor hslBlack(black); | |
void setup() | |
{ | |
Serial.begin(115200); | |
while (!Serial); // wait for serial attach | |
Serial.println(); | |
Serial.println("Initializing..."); | |
Serial.flush(); | |
// this resets all the neopixels to an off state | |
strip.Begin(); | |
strip.Show(); | |
Serial.println(); | |
Serial.println("Running..."); | |
} | |
void loop() | |
{ | |
for (float hue = 0; hue < 1.0f; hue = hue + 0.16666f) { | |
HslColor colour(hue, 1.0f, 0.5f); | |
for (int led = 0; led < PixelCount; led = led + 1) { | |
strip.SetPixelColor(led, colour); | |
strip.Show(); | |
delay(20); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment