Arduino Code

Adafruit's NeoPixel library comes with a pre-installed rainbow animation effect.  You'll need to make just a few edits to the code.

If this is your first time using Arduino, you'll need to download and install the free software and the NeoPixel library.  

Here's a guide that will walk you through installing Arduino and getting the Gemma board set up.

And..

Here's a detailed NeoPixel library installation guide.

Once you've got Arduino installed and the NeoPixel library installed, open Arduino and choose:

File > Examples > Adafruit NeoPixel > strandtest

This will open up a window with the code we want to modify.

First, find this line near the top of the strandtest code:

Download: file
#define PIN 6

Since we soldered our LED strand to pin 1, we'll change the pin number from 6 to 1.

Download: file
#define PIN 1

Next, look for this line:

Download: file
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

This is where we tell the Gemma how many LEDs we soldered onto pin 1.  The default is 60.  Change this to reflect the number of pixels you have in ONE strip.

Why count just one strip?  We soldered both our strips to pin 1, so they will show the same code at the same time.  So even if you have 40 NeoPixels total, we'll want to tell the microcontroller we have 20 since that's how many are in each strip.

Download: file
Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, PIN, NEO_GRB + NEO_KHZ800);

The strandtest code runs a series of animations, doing color wipes and chase animations along with the rainbow.  For this project I want nothing but rainbows, so we'll go into the code and comment out all the other animations.

Find this section:

Download: file
void loop() {
  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127, 0, 0), 50); // Red
  theaterChase(strip.Color(0, 0, 127), 50); // Blue

  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
}

The loop() function is the part of the code that will run continuously on the Gemma.  Right now it's set up to cycle through three colorWipe() animations (the fourth one is already commented out), then three theaterChase() animations, then we get to rainbow()

Add two slashes:

//

...to the beginning of each animation you do NOT want to show.  Your code will look like this:

Download: file
void loop() {
  // Some example procedures showing how to display to the pixels:
  //colorWipe(strip.Color(255, 0, 0), 50); // Red
  //colorWipe(strip.Color(0, 255, 0), 50); // Green
  //colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  // Send a theater pixel chase in...
  //theaterChase(strip.Color(127, 127, 127), 50); // White
  //theaterChase(strip.Color(127, 0, 0), 50); // Red
  //theaterChase(strip.Color(0, 0, 127), 50); // Blue

  rainbow(20);
  //rainbowCycle(20);
  //theaterChaseRainbow(50);
}

You can also mess with the speed of the rainbow animation.  Try a larger or smaller number in place of the (20) to see what works for you.

Now, plug your Gemma into your computer via the USB port.  Go to Tools > Board and select Adafruit Gemma M0.

Don't see it there?  Be sure you followed all the instructions on this page.

Double click the reset button on the Gemma, and at the same time, click the upload button in Arduino.  You'll see a second LED light up on the face of the Gemma, in red, and it will flicker a bit.  That's how you know it's working!  

This guide was first published on Mar 29, 2018. It was last updated on Mar 29, 2018. This page (Arduino Code) was last updated on Aug 29, 2019.