I have been playing with the NeoPixels and Trinket for a while now to make some pretty cool blinky things :-)
I wanted to try to make something that I could have the Pixels Cycle through colors at the push of a button. They would start Red, then with a button push go to Orange, another push of the button would go to Yellow, and so on.
What would the best way to code this be so I could go through all 7 colors and then cycle back to the original color? Also any recomendations on a button? Can I use a momentary button, or something like a slide on/off switch?
I currently have a project that uses a slide on/off to toggle modes, I will copy the example code below.
Thanks,
Joshua
Code: Select all
//NeoPixel LED HALO Sword with Switch Mode
#include <Adafruit_NeoPixel.h>
//Settings:
#define PIN 0 //The Pin out your Neopixel DIN strip/stick is connected to (Default is 6)
#define TPIXEL 23 //The total amount of pixel's/led's in your connected strip/stick
//To change the timing of between pulses change the number in int 'refresh', to change the speed of it scrolling change the number in int 'wait_T' and 1000 is equal to 1second.
int wait_T=40; //This is the delay between moving back and forth and per pixel
int refresh=400;
int PixelCount=23; //Set this to the AMOUNT of Led's/strip you have or want to use on your strip And It can be used to tell where to Stop then return the eye at in the strip
int Pixel_Start_End=0; //Set this to where you want it to Start/End at
boolean UsingBar = false; //Set this to true If you are using the 8x1 Neopixel Bar Or you want to only use 3 leds for the scanner.
Adafruit_NeoPixel strip = Adafruit_NeoPixel(23, PIN);
//
// RF Pins
//
int inPinA = 2; // the number of the input pin (RX) - Button "A"
int counterA = 0; // how many times we have seen new value
int readingA; // the current value read from the input pin A
int current_stateA = LOW; // the debounced input value
// the following variable is a long because the time, measured in milliseconds,
// will quickly become a bigger number than can be stored in an int.
long timeA = 0; // the last time the output pin was sampled
int debounce_count = 2; // number of millis/samples to consider before declaring a debounced input
void setup()
{
strip.begin();
colorWipe(strip.Color(0, 255, 32), 0); // Red //Default Seagreen for Powerup.
strip.show(); // Initialize all strip to 'off'
int i;
pinMode(inPinA, INPUT);
}
void loop()
{
if (digitalRead(inPinA) == HIGH)
{
Do Stuff;
}
else
{
Do Other Stuff;
}
}
// 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);
}
}