#4878728
TL;DR at bottom.
So I'm pretty new to both electronics and Arduino coding. I am helping a friend with his reboot pack build, and while he does the crafting work I offered to help with the light programming. I got the hardware part figured out very quickly, the code, however, is a bit more troublesome.

He initially ordered 2 Arduinos and some NeoPixel Ring Lights (60 LED) + Jewel (7 LED) and the 7 segment LED's from GhostLab42 (viewtopic.php?f=31&t=41215).

I got the 7segment lights working nearly without issue. However I would LIKE to add a switch to it that allows it to switch from like the scrolling code to the counting code, and also have it display random numbers while scrolling.

I got the NeoPixel lights hooked up and with the example code I know they work. The NeoPixel lights have an example library but does a poor job explaining itself. I just want to have it so I can have a switch from pulsing lights to scrolling/chasing lights (Neither of which I have good code for) and maybe a rainbow startup.

A (probably farfetched) desire is to have all this code running on ONE arduino. If anyone knows how to make this happen let me know. We have a second board ANYWAYS so no big deal if this isn't possible.

TL;DR:
-Need code to have a switch to swap codings on 7 segment displays
-Need NeoPixel Code for movie-like effects
-Want to run all code from one arduino if possible (I have 2 anyways)

Literally any help is appreciated and may help any others who cannot code very well, like myself. I will credit people in the code as well!
#4878991
I am gonna be breaking posts down into smaller thoughts and such. That way I don't have to write a book and we can discuss as we go.

First I am not a pro by any means. I have successfully coded scrolling and rainbow as you mentioned. I put them on an adafruit gemma board.

I used Bluetooth to switch between the different light modes. I can help with that. (I don't know how you will signal your board to switch modes.) I can choose different colors and modes from my phone. In the near future I will teach myself IR so I can reduce costs of my components.

I did not get the rainbow and the scrolling modes on at the same time. The coding space on the gemma is pretty tight.

I have the Trinket Pro but have not successfully written code to that yet.

If size is an issue... There is a product out there, tiny circuits, that has the same chip as the arduino but is the size of a dime. I plan on getting myself a few of those to "play" with eventually. That controller is limited with data pins though.
#4879004
Azuran, you said you got 2 Arduinos. Would you be able to tell me which ones? Uno, etc.?

I am working on code for my Reboot pack as well. One good way to switch between modes in an attempt to get the NeoPixels to display different patterns is with a simple momentary (push button) switch: https://www.adafruit.com/products/1683

The code can be written such that each time the button is pressed, the LEDs are "told" to do a new pattern. This is done by assigning a variable in the code whose only job is to keep track of how many times the button has been pressed. Something like:
Code: Select all
int buttonState;

is what I like to use.

Initially, buttonState = 0.

When the push button switch is pressed once, buttonState is then set to 1:
Code: Select all
 [switch is pressed]
buttonState = 1;
[code that tells NeoPixels to switch to a new pattern]

There's a really good tutorial for this that helped me: http://www.ladyada.net/learn/arduino/lesson5.html It will take you a while go to go through, but at the end you should have the building blocks for what you're looking for.


I have not finished the code for my NeoPixels, as I've got a Mini Skinny 144LED strip ordered that hasn't come in yet. I will happily share my code when I get it done, though.
deejeerie liked this
#4879099
Any and all help is appreciated.
Azuran and myself are building the reboot proton pack for anime weekend Atlanta this year.
Due to time constraints I asked him to help with the aurdino and Lights so I can work on the pack building.
The aurdino is a UNO version.
This is our first time using a aurdino and thus the programming is a little confusing for us.
We have seen snippets of code but it still throws us for a loop.
Trying to get the lights to scan in a slow clockwise circle and maybe flash white or a different color when a push button is pressed and held.
And if we get it figured out maybe a startup animation but that is dreaming big.
In the mean time any help is beyond appreciated!

The pack is coming along nicely but slowly.
One of the hardest parts I am running into is the thrower not sure what to do about building that since is such a unique shape but Hopefully will figure something out.

Image

Its in still rough shape but each day I am adding a little more to get it right.
MonaLS liked this
#4879163
Hi Azuran, there's a bit of a learning curve with this Arduino stuff, and I understand how intimidating it can feel.

First thing you'll want to do is install the Arduino IDE on your computer (https://www.arduino.cc/en/Main/Software). This is what you will use to program your Uno.

Connect your Uno to one of the USB ports on your computer using a USB A-B cable: https://www.adafruit.com/products/62

After you're got the IDE installed, open it up and set it for communicating with your Uno.

Under Tools --> Board, select "Arduino/Genuino Uno"
Under Tools --> Port, select whichever port is highlighted with your Uno (mine is COM7)
Under Tools --> Programmer, select "USBtinyISP"

Now, since you're using NeoPixels, you'll want to download the Adafruit NeoPixel library. A library is just another program someone has written to help with the code so you don't have to worry about it. Libraries do a lot of the behind-the-scenes heavy lifting. Download and install the NeoPixel library into the Arduino IDE libraries folder on your computer. https://github.com/adafruit/Adafruit_NeoPixel

There's a green button on the right hand side of this page that says "Clone or download." Download the .zip file and save it to your Arduino IDE libraries folder.

Now, go back to your Arduino IDE window. Under Sketch --> Include Library --> Add .ZIP library, navigate to where you saved the NeoPixel .zip file and select it (you may need to close and reopen the Arduino IDE to get it to show up).

Go back to Sketch --> Include Library and find "Adafruit NeoPixel" in the list. Click on it. You should see some code like
Code: Select all
#include <Adafuit_Neopixel.h>
up at the top of your sketch.

Well done! This sketch is now ready to have code written to control your NeoPixels.

Clear as mud? Let me know if you have questions!
MonaLS liked this
#4879329
This is a rainbow code that I have used. It was created for use with a Adafruit Gemma but should work fine on your Uno.
Just remember to define the pins correctly and enter the correct number of pixels/leds.

#include <Adafruit_NeoPixel.h>

#define PIN 1

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: Avoid connecting on a live circuit...if you must, connect GND first.

void setup() {
strip.begin();
strip.setBrightness(100); //adjust brightness here
strip.show(); // Initialize all pixels to 'off'
}

void loop() {
rainbowCycle(20);
}


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



// 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) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
#4879381
I changed the "rainbow" example sketch deejeerie posted to--I hope--be a little more beginner friendly. Adafruit is great because they provide libraries and a lot of example code, but they could stand to have more explanation and best-practices in their example sketches.

I like to have my named variables at the top of my program as much as possible, so that if I decide I want to change a value, I only have to change it in one place. That's why stuff like the number of NeoPixels (NUMPIXELS), the NeoPixel brightness (BRIGHTNESS), and data pin (PIN) are all at the top. If I decided to add a 144NeoPixel strip to my 60 NeoPixel ring and Jewel, all I would have to do is change one number, NUMPIXELS, from 67 to 211. Same with the brightness of all the NeoPixels. If I am walking around a Con during the day, I might set BRIGHTNESS to 200. But if I'm out on Halloween, maybe I take it down to 75. Just change one number, upload the changes to the Uno, and bam, done.
Code: Select all
    #include <Adafruit_NeoPixel.h>
    
    #define NUMPIXELS 67   //This is the TOTAL number of NeoPixels you have on your strip.  A ring + a Jewel = 60 + 7 = 67 

    #define PIN 13         //This is the Uno pin your data wire is connected to.  I use 13 because it's nice and out of the way.

    #define BRIGHTNESS 100      //This is how bright the NeoPixels should be.  255 is brightest, 0 is off.

    #define RAINBOWWAIT 20    //Arduino times are in milliseconds.  So a value of 20 means a 20 ms wait every time     
                                                             //"delay()" is called.  A value of 1000 means a wait time of 1 s.  The smallest allowable
                                                             // value is 1, or 0.001 seconds.
   
    // Parameter 1 = number of pixels in strip
    // Parameter 2 = Arduino pin number (most are valid)
    // Parameter 3 = pixel type flags, add together as needed:
    //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
    //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
    //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
    //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
     
    // IMPORTANT: Avoid connecting on a live circuit...if you must, connect GND first.
     
    void setup() {
      strip.begin();
      strip.setBrightness(BRIGHTNESS);
      strip.show(); // Initialize all pixels to 'off'
    }
     
    void loop() {
      rainbowCycle(RAINBOWWAIT);
    }
     
     
    // 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();              //This takes the bits from the code directly above and "pushes" those colors out to the NeoPixels
        delay(wait);
      }
    }
     
    // 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) {
      if(WheelPos < 85) {
       return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
      } else if(WheelPos < 170) {
       WheelPos -= 85;
       return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
      } else {
       WheelPos -= 170;
       return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
      }
    }
If you copy this code, paste it into your Arduino IDE program, and upload it to your Uno, you should see your NeoPixels blasting out some neat color. Play around with the parameters BRIGHTNESS, RAINBOWWAIT, and NUMPIXELS. What happens when you put different numbers in?

When you say you want code for the movie effects, do you just mean the red clockwise pulsing on the back of the proton packs? And by "rainbow startup," do you mean you want the pack to quickly go through the rainbow, then "land" on red and do pulses?
#4879482
godspeed13 wrote:Exactly . I wanted it on start up to quickly go through a rainbow then stay on red and in a slow clockwise motion .
I was also hoping that when a momentary push button was held it would flash white and blue until released then go back to the slow clockwise red like in the movie .
Understood. I'll start working on it.
#4879532
Heres my latest arduino sketch i used for the neopixel strip/ring lights

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 6
#define NUM_PIXELS 100
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRBW + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.

// NOTE
// NUMBER_COMETS x (COMET_LENGTH + COMET_SPACING) must be <= TOTAL_COMET_PIXELS
// The number of pixels in each comet
#define COMET_LENGTH 12
// The number of comets
#define NUMBER_COMETS 3
// The number of pixels between each comet
#define COMET_SPACING 8
// The total number of pixels in the strip dedicated to comets
#define TOTAL_COMET_PIXELS 60

// The direction of the comet 0 or 1
#define COMET_DIRECTION 0
// The max comet brightness
#define MAX_COMET_BRIGHTNESS 255
// The comet speed
#define SPEED 50


byte rgbyRedLevels[NUM_PIXELS];

void InitComet()
{
int iIndex=0;
byte byMasterPos=0;
byte byCometIndex=0;
memset(rgbyRedLevels,0,NUM_PIXELS);


for(byCometIndex = 0; byCometIndex < NUMBER_COMETS; byCometIndex++)
{
#if COMET_DIRECTION
byte byBrightness=0;
#else
byte byBrightness = MAX_COMET_BRIGHTNESS;
#endif
// Dim comet by length
byte byDim = MAX_COMET_BRIGHTNESS / COMET_LENGTH;
for( iIndex = 0 ; iIndex < COMET_LENGTH ; iIndex++)
{
rgbyRedLevels[byMasterPos++] = byBrightness;
#if COMET_DIRECTION
byBrightness += byDim;
#else
byBrightness -= byDim;
#endif
}
byMasterPos += COMET_SPACING;
}
}


void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code

Serial.begin(9600); // open the serial port at 9600 bps:
strip.begin();
strip.show(); // Initialize all pixels to 'off'

InitComet();

}

#if COMET_DIRECTION
void ProcessCometsDir()
{
byte iIndex=0;
byte byLast=0;
byte byDestPixel=0;
byte byOld=0;

byLast= rgbyRedLevels[TOTAL_COMET_PIXELS-1]; // Preserve the contents of the last pixel

for(iIndex =TOTAL_COMET_PIXELS-1 ; iIndex > 0 ; iIndex--)
{
rgbyRedLevels[iIndex] = rgbyRedLevels[iIndex-1];
}
rgbyRedLevels[0]= byLast; // Put what was the last pixel intio the first

for(iIndex =0 ; iIndex <TOTAL_COMET_PIXELS ; iIndex++)
{
strip.setPixelColor(iIndex,rgbyRedLevels[iIndex],0,0 );
}
strip.show();
delay(SPEED);
}
#else
void ProcessCometsDir()
{
byte iIndex=0;
byte byLast=0;
byte byDestPixel=0;
byte byOld=0;

byLast= rgbyRedLevels[0]; // Preserve the contents of the last pixel

for(iIndex =0 ; iIndex < TOTAL_COMET_PIXELS-1 ; iIndex++)
{
rgbyRedLevels[iIndex] = rgbyRedLevels[iIndex+1];
}
rgbyRedLevels[TOTAL_COMET_PIXELS-1]= byLast; // Put what was the last pixel intio the first

for(iIndex =0 ; iIndex <TOTAL_COMET_PIXELS ; iIndex++)
{
strip.setPixelColor(iIndex,rgbyRedLevels[iIndex],0,0 );
}
strip.show();
delay(SPEED);
}
#endif




void loop()
{
ProcessCometsDir();
}
Last edited by tommyb345 on September 3rd, 2016, 6:06 am, edited 1 time in total.
#4879534
and heres my latest sketch for my displays
this starts up with a scrolling display message on the top display and then proceeds to the randomizing displays
nice looking 3d printed parts by the way hehe

#include <GhostLab42Reboot.h>
#include <Wire.h>

GhostLab42Reboot reboot;

void setup()
{
reboot.begin();
reboot.write(1, "126.2");
reboot.write(2, "-42.9");

// Turn down the brightness of the main displays
reboot.setDisplayBrightness(0, 60);
reboot.setDisplayBrightness(1, 100);
reboot.setDisplayBrightness(2, 60);
}

void loop()
{
// String to be scrolled across the six digit display
// Need the extra spaces to make the scrolling smooth
String displayText = " Who ya gonna call? Ghostbusters! ";

// A NOTE ABOUT SCROLLING:
// This works fine if there are not any periods/decimals, since a period/decimal
// is either considered part of the previous character or its own character if
// it is in the first position of the display (in which case there is technically
// a "space" in front of it)
// Check out ex4_scrollingtextadvanced instead if you are planning on scrolling a
// string with a period/decimal

// Commence scrolling
for (int i = 0; i < displayText.length(); i++)
{
reboot.write(0, displayText.substring(i, i + 6));
delay(250);
}

// Clear and start over
reboot.resetDisplay(0);

String countStr;
int count = 2087;

for (int i = 0; i < 1000; i++)
{
// Count down
reboot.write(0, String(120999 - i));

// Count up with leading 0s really fast
countStr = "000" + String(16 * i);
reboot.write(1, countStr.substring(countStr.length() - 4));

// Show a number that is about 2087 but moves around randomly by a few counts
// Slow the update down so it changes more slowly
if ((i % 30) == 0)
{
count = 2087 + random(-2, 3);
}

reboot.write(2, String(count));

delay(30);
}}
MightyAni liked this
#4879876
@tommyb: The seven segment code is perf, thanks so much for that! The Idle comet for the neopixels is also good, uploaded the sketch and it's a nice idle animation. You rock!

@mightyani: Thanks for all your help so far as well, I knew the basic library and uploading example sketch to the arduino and doing minor edits to example code, but I'm not seasoned enough to write new code or go from scratch. Unfortunately for the time frame I have I can't really do enough research to do coding. You said you'd help writing a sketch to his specifications and if you could you'd also rock very much :)

The people here at GBFans are amazing!
#4879887
Azuran wrote: @mightyani: Thanks for all your help so far as well, I knew the basic library and uploading example sketch to the arduino and doing minor edits to example code, but I'm not seasoned enough to write new code or go from scratch. Unfortunately for the time frame I have I can't really do enough research to do coding. You said you'd help writing a sketch to his specifications and if you could you'd also rock very much :)
For a really quick solution to your problem, I've got a bit of a sketch from my lightsaber build that I think we can splice into Tommyb's "red comet" sketch so that your NeoPixels will flash crazy blue and white when you hold down a momentary button and then go back to comets when the button is released. I think we can also just lift the code from the NeoPixel library's example and jam it in there, too.

Give me a few days and I should have a full sketch you can just copy and paste to your IDE.

Thanks for your patience~~ :love:
#4880014
Alright everyone, I've got a lot of cool stuff cooking up over here, if you'd just like to turn your heads, uhhhhhhh:

Code: Select all
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIXELDATAPIN 6
#define NUMPIXELS 60                                                                                  
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIXELDATAPIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.

const int buttonPin = 2;		//The input pin is where the pushbutton switch is located

int val;					//This variable stores the state of the input pin
int buttonState = 0;		//Store the state of the switch
int flashMode = 0;			//0 means the LEDs are doing red comets...
						//...and 1 means the LEDs are flashing hues of blue and white

int delayval;				//How quick will blue and white flash?
int r, g, b;
int low = 0;				//The bottom of the color range
int range = 255;			//The spread of the color range
int delayshort = 20;		//Fast flashing, 20 ms delay
int delaylong = 50;			//Slower flashing, 40 ms delay

// NOTE
// NUMBER_COMETS x (COMET_LENGTH + COMET_SPACING) must be <= TOTAL_COMET_PIXELS
// The number of pixels in each comet
#define COMET_LENGTH 12
// The number of comets
#define NUMBER_COMETS 3
// The number of pixels between each comet
#define COMET_SPACING 8
// The total number of pixels in the strip dedicated to comets
#define TOTAL_COMET_PIXELS 60
// The direction of the comet 0 or 1
#define COMET_DIRECTION 1 
// The max comet brightness
#define MAX_COMET_BRIGHTNESS 255
// The comet speed
#define SPEED 60


void setup() {
	// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
	if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
	// End of trinket special code
	pinMode(buttonPin, INPUT);		//Tell the Arduino the pushbutton is an input

	Serial.begin(9600); //open the serial port at 9600 bps: 
	strip.begin();		//Initialize the NeoPixel library
	strip.show();		//Initialize all pixels to 'off'
	
	buttonState = digitalRead(buttonPin);	//Read the initial state of the pushbutton

	randomSeed(analogRead(0));

	InitComet();
}

byte rgbyRedLevels[NUMPIXELS];

void InitComet(){
	int iIndex = 0;
	byte byMasterPos = 0;
	byte byCometIndex = 0;
	memset(rgbyRedLevels, 0, NUMPIXELS);


	for (byCometIndex = 0; byCometIndex < NUMBER_COMETS; byCometIndex++){
#if COMET_DIRECTION
		byte byBrightness = 0;
#else
		byte byBrightness = MAX_COMET_BRIGHTNESS;
#endif
		// Dim comet by length
		byte byDim = MAX_COMET_BRIGHTNESS / COMET_LENGTH;
		
		for (iIndex = 0; iIndex < COMET_LENGTH; iIndex++){
			rgbyRedLevels[byMasterPos++] = byBrightness;
#if COMET_DIRECTION 
			byBrightness += byDim;
#else
			byBrightness -= byDim;
#endif 
		}
		byMasterPos += COMET_SPACING;
	}
}


#if COMET_DIRECTION 
void ProcessCometsDir(){
	byte iIndex = 0;
	byte byLast = 0;
	byte byDestPixel = 0;
	byte byOld = 0;

	byLast = rgbyRedLevels[TOTAL_COMET_PIXELS - 1]; // Preserve the contents of the last pixel

	for (iIndex = TOTAL_COMET_PIXELS - 1; iIndex > 0; iIndex--){
		rgbyRedLevels[iIndex] = rgbyRedLevels[iIndex - 1];
	}
	rgbyRedLevels[0] = byLast; // Put what was the last pixel intio the first

	for (iIndex = 0; iIndex <TOTAL_COMET_PIXELS; iIndex++){
		strip.setPixelColor(iIndex, rgbyRedLevels[iIndex], 0, 0);
	}
	strip.show();
	delay(SPEED);
}

#else
void ProcessCometsDir()
{
	byte iIndex = 0;
	byte byLast = 0;
	byte byDestPixel = 0;
	byte byOld = 0;

	byLast = rgbyRedLevels[0]; // Preserve the contents of the last pixel

	for (iIndex = 0; iIndex < TOTAL_COMET_PIXELS - 1; iIndex++)
	{
		rgbyRedLevels[iIndex] = rgbyRedLevels[iIndex + 1];
	}
	rgbyRedLevels[TOTAL_COMET_PIXELS - 1] = byLast; // Put what was the last pixel intio the first

	for (iIndex = 0; iIndex <TOTAL_COMET_PIXELS; iIndex++)
	{
		strip.setPixelColor(iIndex, rgbyRedLevels[iIndex], 0, 0);
	}
	strip.show();
	delay(SPEED);
}
#endif

void BlueWhiteFlashing() {
	//Randomly choose the color the NeoPixels will have while the pushbutton switch is pressed
	//Take that color and apply it to all NeoPixels
	r = low + random(0, 100);		//The red channel.  Brightness goes between 0 (off) and its
								//contribution to white, 100.
	g = r;						//The green channel, same as red
	b = random(25, 150);			//The blue channel.  Want to have a lot of blues.

	//For a set of NeoPixels the first NeoPixel is 0, the second is 1, all the way up to
	//the count of NeoPixels, minus one.
	for (int i = 0; i < NUMPIXELS; i++) {
		//RGB values from a minimum of (0, 0, 0) up to a maximum of (255, 255, 255)
		strip.setPixelColor(i, strip.Color(r, g, b));	//Pulse the NeoPixels, hues of blue
	}
	strip.show();		//Send the updated pixel color out to the NeoPixel ring

	delayval = random(delayshort, delaylong);
	delay(delayval);	//Delay for a period of time before the next flash, in milliseconds

}


void loop() {

	val = digitalRead(buttonPin);		//Read the state of the pushbutton and store it in val

	if (val == HIGH) {			//If the button is not pressed down...
		flashMode = 0;			//...then we should be seeing red comets
	} else if (val == LOW) {		//But if the button IS pressed down 
		flashMode = 1;			//...we need to queue up the blue and white flashes.
	}
	
	if (flashMode == 0) {
		ProcessCometsDir();
	}

	if (flashMode == 1) {		//When the button IS pressed down and flashMode is on...
		BlueWhiteFlashing();	//...show blue and white flashes.

	}

	buttonState = val;				//Save the pushbutton's new state as our variable so we can check it on the next loop.
}


I took some of tommysb's code from above and added in a random flashing of the NeoPixels between white and different hues of blue.

***Hook the NeoPixel data line up to pin 6 on your Uno.

***To initiate the flashing, you need to have a momentary pushbutton switch connected to pin 2 on your Uno. Don't forget the appropriate resistors coming off your switch: a 10 kiloohm one between your switch and +5V, and a 100 ohm one between your switch and pin 2, with a lead to GND on the same pin side as the 10 kiloohm resistor, like this

Image



Mind you, I only tested this code with a NeoPixel 60 ring, so I haven't seen its behavior with the Jewel added in. It shouldn't be a problem, just change NUMPIXELS to 67 instead of 60 and hook up the ring and Jewel in series through their "data in" and "data out" soldering pads.

I'd love feedback about this sketch, and many thanks to tommyb for doing the heavy lifting on the red comet part of it.


EDIT: Crud. I forgot about the rainbow startup part. Will add that in later, but I wanted you to have this part of the code now since I know you're under a time crunch.
#4880435
Alright, here it is with a rainbow color startup/reset animation. I just took some code from the NeoPixels "strandtest" example, modified it a bit, and jammed it into my and tommyb's code from the post above.

Enjoy!
Code: Select all
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIXELDATAPIN 6
#define NUMPIXELS 60                                                                                  
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIXELDATAPIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.

const int buttonPin = 2;		//The input pin is where the pushbutton switch is located

int val;					//This variable stores the state of the input pin
int buttonState = 0;		//Store the state of the switch
int flashMode = 0;			//0 means the LEDs are doing red comets...
						//...and 1 means the LEDs are flashing hues of blue and white

int delayval;				//How quick will blue and white flash?
int r, g, b;
int low = 0;				//The bottom of the color range
int range = 255;			//The spread of the color range
int delayshort = 20;		//Fast flashing, 20 ms delay
int delaylong = 50;			//Slower flashing, 40 ms delay

// NOTE
// NUMBER_COMETS x (COMET_LENGTH + COMET_SPACING) must be <= TOTAL_COMET_PIXELS
// The number of pixels in each comet
#define COMET_LENGTH 12
// The number of comets
#define NUMBER_COMETS 3
// The number of pixels between each comet
#define COMET_SPACING 8
// The total number of pixels in the strip dedicated to comets
#define TOTAL_COMET_PIXELS 60
// The direction of the comet 0 or 1
#define COMET_DIRECTION 1 
// The max comet brightness
#define MAX_COMET_BRIGHTNESS 255
// The comet speed
#define SPEED 60


void setup() {
	// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
	if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
	// End of trinket special code
	pinMode(buttonPin, INPUT);		//Tell the Arduino the pushbutton is an input

	Serial.begin(9600); //open the serial port at 9600 bps: 
	strip.begin();		//Initialize the NeoPixel library
	strip.show();		//Initialize all pixels to 'off'
	
	buttonState = digitalRead(buttonPin);	//Read the initial state of the pushbutton

	randomSeed(analogRead(0));

	rainbow(30);

	InitComet();
}

byte rgbyRedLevels[NUMPIXELS];

void InitComet(){
	int iIndex = 0;
	byte byMasterPos = 0;
	byte byCometIndex = 0;
	memset(rgbyRedLevels, 0, NUMPIXELS);


	for (byCometIndex = 0; byCometIndex < NUMBER_COMETS; byCometIndex++){
#if COMET_DIRECTION
		byte byBrightness = 0;
#else
		byte byBrightness = MAX_COMET_BRIGHTNESS;
#endif
		// Dim comet by length
		byte byDim = MAX_COMET_BRIGHTNESS / COMET_LENGTH;
		
		for (iIndex = 0; iIndex < COMET_LENGTH; iIndex++){
			rgbyRedLevels[byMasterPos++] = byBrightness;
#if COMET_DIRECTION 
			byBrightness += byDim;
#else
			byBrightness -= byDim;
#endif 
		}
		byMasterPos += COMET_SPACING;
	}
}


#if COMET_DIRECTION 
void ProcessCometsDir(){
	byte iIndex = 0;
	byte byLast = 0;
	byte byDestPixel = 0;
	byte byOld = 0;

	byLast = rgbyRedLevels[TOTAL_COMET_PIXELS - 1]; // Preserve the contents of the last pixel

	for (iIndex = TOTAL_COMET_PIXELS - 1; iIndex > 0; iIndex--){
		rgbyRedLevels[iIndex] = rgbyRedLevels[iIndex - 1];
	}
	rgbyRedLevels[0] = byLast; // Put what was the last pixel intio the first

	for (iIndex = 0; iIndex <TOTAL_COMET_PIXELS; iIndex++){
		strip.setPixelColor(iIndex, rgbyRedLevels[iIndex], 0, 0);
	}
	strip.show();
	delay(SPEED);
}

#else
void ProcessCometsDir()
{
	byte iIndex = 0;
	byte byLast = 0;
	byte byDestPixel = 0;
	byte byOld = 0;

	byLast = rgbyRedLevels[0]; // Preserve the contents of the last pixel

	for (iIndex = 0; iIndex < TOTAL_COMET_PIXELS - 1; iIndex++)
	{
		rgbyRedLevels[iIndex] = rgbyRedLevels[iIndex + 1];
	}
	rgbyRedLevels[TOTAL_COMET_PIXELS - 1] = byLast; // Put what was the last pixel intio the first

	for (iIndex = 0; iIndex <TOTAL_COMET_PIXELS; iIndex++)
	{
		strip.setPixelColor(iIndex, rgbyRedLevels[iIndex], 0, 0);
	}
	strip.show();
	delay(SPEED);
}
#endif

void BlueWhiteFlashing() {
	//Randomly choose the color the NeoPixels will have while the pushbutton switch is pressed
	//Take that color and apply it to all NeoPixels
	r = low + random(0, 100);		//The red channel.  Brightness goes between 0 (off) and its
								//contribution to white, 100.
	g = r;						//The green channel, same as red
	b = random(25, 150);			//The blue channel.  Want to have a lot of blues.

	//For a set of NeoPixels the first NeoPixel is 0, the second is 1, all the way up to
	//the count of NeoPixels, minus one.
	for (int i = 0; i < NUMPIXELS; i++) {
		//RGB values from a minimum of (0, 0, 0) up to a maximum of (255, 255, 255)
		strip.setPixelColor(i, strip.Color(r, g, b));	//Pulse the NeoPixels, hues of blue
	}
	strip.show();		//Send the updated pixel color out to the NeoPixel ring

	delayval = random(delayshort, delaylong);
	delay(delayval);	//Delay for a period of time before the next flash, in milliseconds

}

void rainbow(int wait) {
	uint16_t i, j;
	for (j = 0; j < 256; j++){
		for (i = 0; i < NUMPIXELS; i++) {
			strip.setPixelColor(i, Wheel(j & 255));
		}
	strip.show();
	delay(wait);
	}
}

// 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 = 245 - 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);
}

void loop() {

	val = digitalRead(buttonPin);	//Read the state of the pushbutton and store it in val

	if (val == HIGH) {			//If the button is not pressed down...
		flashMode = 0;			//...then we should be seeing red comets
	} else if (val == LOW) {		//But if the button IS pressed down 
		flashMode = 1;			//...we need to queue up the blue and white flashes.
	}
	
	if (flashMode == 0) {
		ProcessCometsDir();
	}

	if (flashMode == 1) {		//When the button IS pressed down and flashMode is on...
		BlueWhiteFlashing();	//...show blue and white flashes.
	}

	buttonState = val;			//Save the pushbutton's new state as our variable so we can check it on the next loop.
}

Someone ID'd them on Facebook first, there w[…]

Two specific ideas I have are basically holiday sp[…]

While waiting impatiently for Frozen Empire to rel[…]

Make it that pack, sell it for $599. (While I […]