The Arduino code presented below works equally well on all versions of GEMMA: v1, v2 and M0. But if you have an M0 board, consider using the CircuitPython code on the next page of this guide, no Arduino IDE required!

To program GEMMA, make sure you have set up the Arduino IDE as explained in the "Introducing GEMMA" guide. Also, you’ll need the NeoPixel library installed as explained in the NeoPixel Überguide.

Above is a diagram numbering the NeoPixels in their programatic order. It's handy for writing animations that seem to flow between rings, like the basic sine wave animation here:

// SPDX-FileCopyrightText: 2017 Dano Wall for Adafruit Industries
// SPDX-FileCopyrightText: 2017 Becky Stern for Adafruit Industries
//
// SPDX-License-Identifier: MIT

//Basic sine wave animation for NeoPixel Ring Bangle Bracelet
//by Dano Wall and Becky Stern for Adafruit Industries
#include <Adafruit_NeoPixel.h>

#define PIN       1 // Marked D1 on GEMMA
#define NUM_LEDS 64

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type:
//   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_LEDS, PIN, NEO_GRB);

uint32_t color = strip.Color(75, 250, 100); // Change RGB color value here

// These are the pixels in order of animation-- 36 pixels in total:
int sine[] = {
   4,  3,  2,  1,  0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28,
  36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60 };

void setup() {
  strip.begin();
  strip.show();            // Initialize all pixels to 'off'
  strip.setBrightness(40); // 40/255 brightness (about 15%)
}

void loop() {
  for(int i=0; i<36; i++) {
    strip.setPixelColor(sine[i], color);             // Draw 'head' pixel
    strip.setPixelColor(sine[(i + 36 - 8) % 36], 0); // Erase 'tail'
    strip.show();
    delay(40);
  }
}
Here's another fun animation, it's similar to the sine wave but loops back around on itself when it gets to the fourth ring in a "figure eight."
// SPDX-FileCopyrightText: 2017 Dano Wall for Adafruit Industries
// SPDX-FileCopyrightText: 2017 Becky Stern for Adafruit Industries
//
// SPDX-License-Identifier: MIT

//Figure-Eight animation for Neopixel Ring Bangle Bracelet
//By Dano Wall and Becky Stern for Adafruit Industries
#include <Adafruit_NeoPixel.h>

#define PIN       1 // Marked D1 on GEMMA
#define NUM_LEDS 64

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type:
//   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_LEDS, PIN, NEO_GRB);

uint32_t color = strip.Color(5, 250, 200); // Change RGB color value here

// Array of pixels in order of animation - 70 in total:
int sine[] = {
   4,  3,  2,  1,  0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28,
  36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60,
  61, 62, 63, 48, 49, 50, 51, 52, 44, 43, 42, 41, 40, 39, 38, 37, 36, 28,
  29, 30, 31, 16, 17, 18, 19, 20, 12, 11, 10,  9,  8,  7,  6,  5 };

void setup() {
  strip.begin();
  strip.show();            // Initialize all pixels to 'off'
  strip.setBrightness(40); // 40/255 brightness (about 15%)
}

void loop() {
  for(int i=0; i<70; i++) {
    strip.setPixelColor(sine[i], 0);                 // Erase 'tail'
    strip.setPixelColor(sine[(i + 10) % 70], color); // Draw 'head' pixel
    strip.show();
    delay(60);
  }
}
This code randomly flashes pixels in three colors of your choice.
// SPDX-FileCopyrightText: 2017 Dano Wall for Adafruit Industries
// SPDX-FileCopyrightText: 2017 Becky Stern for Adafruit Industries
//
// SPDX-License-Identifier: MIT

//Random Flash animation for Neopixel Ring Bangle Bracelet
//by Dano Wall and Becky Stern for Adafruit Industries
//based on the Sparkle Skirt, minus the accelerometer
#include <Adafruit_NeoPixel.h>

#define PIN       1 // Marked D1 on GEMMA
#define NUM_LEDS 64

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type:
//   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_LEDS, PIN, NEO_GRB);

// Here is where you can put in your favorite colors that will appear!
// just add new {nnn, nnn, nnn}, lines. They will be picked out randomly
uint8_t myColors[][3] = {
  {232, 100, 255}, // purple
  {200, 200,  20}, // yellow
  { 30, 200, 200}, // blue
};

// don't edit the line below
#define FAVCOLORS sizeof(myColors) / 3

void setup() {
  strip.begin();
  strip.show();            // Initialize all pixels to 'off'
  strip.setBrightness(40); // 40/255 brightness (about 15%)
}

void loop() {
  flashRandom(5); // Number is 'wait' delay, smaller num = faster twinkle
}

void flashRandom(int wait) {

  // pick a random favorite color!
  int c     = random(FAVCOLORS);
  int red   = myColors[c][0];
  int green = myColors[c][1];
  int blue  = myColors[c][2];

  // get a random pixel from the list
  int j = random(strip.numPixels());

  // now we will fade in over 5 steps
  for (int x=1; x <= 5; x++) {
    int r = red   * x / 5;
    int g = green * x / 5;
    int b = blue  * x / 5;

    strip.setPixelColor(j, strip.Color(r, g, b));
    strip.show();
    delay(wait);
  }
  // & fade out in 5 steps
  for (int x=5; x >= 0; x--) {
    int r = red   * x / 5;
    int g = green * x / 5;
    int b = blue  * x / 5;

    strip.setPixelColor(j, strip.Color(r, g, b));
    strip.show();
    delay(wait);
  }
  // LED will be off when done (they are faded to 0)
}

This guide was first published on Dec 18, 2013. It was last updated on Apr 16, 2024.

This page (Arduino Code) was last updated on Apr 16, 2024.

Text editor powered by tinymce.