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!

If this is your first time using GEMMA, work through the Introducing GEMMA or Gemma m0 starter guide first; you need to customize some settings in the Arduino IDE. Once you have it up and running (test the 'blink' sketch), then follow the instructions on the following page for installing the NeoPixel library:

NeoPixel Überguide: Arduino Library Installation

Plug in your circuit via USB and test that all LEDs are functioning properly with the NeoPixel example sketch 'strandtest.' Please refer to the Gemma starter guide and the NeoPixel Überguide if you haven't before.

Once you've verified your wiring is correct, load your desired color code or the sketch below that gently pulses the LEDs red.

// SPDX-FileCopyrightText: 2017 Tony Sherwood for Adafruit Industries
// SPDX-License-Identifier: MIT

//fades all pixels subtly
//code by Tony Sherwood for Adafruit Industries

#include <Adafruit_NeoPixel.h>

#define PIN 1

// Parameter 1 = number of pixels in strip
// Parameter 2 = 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(14, PIN, NEO_GRB + NEO_KHZ800);

int alpha; // Current value of the pixels
int dir = 1; // Direction of the pixels... 1 = getting brighter, 0 = getting dimmer
int flip; // Randomly flip the direction every once in a while
int minAlpha = 25; // Min value of brightness
int maxAlpha = 100; // Max value of brightness
int alphaDelta = 5; // Delta of brightness between times through the loop

void setup() {
  strip.begin();; // Initialize all pixels to 'off'

void loop() {
  flip = random(32);
  if(flip > 20) {
    dir = 1 - dir;
  // Some example procedures showing how to display to the pixels:
  if (dir == 1) {
    alpha += alphaDelta;
  if (dir == 0) {
    alpha -= alphaDelta;
  if (alpha < minAlpha) {
    alpha = minAlpha;
    dir = 1;
  if (alpha > maxAlpha) {
    alpha = maxAlpha;
    dir = 0;
  // Change the line below to alter the color of the lights
  // The numbers represent the Red, Green, and Blue values
  // of the lights, as a value between 0(off) and 1(max brightness)
  // EX:
  // colorSet(strip.Color(alpha, 0, alpha/2)); // Pink
  //colorSet(strip.Color(0, 0, alpha)); // Blue
  //colorSet(strip.Color(alpha, alpha/2, 0)); // Yellow
  colorSet(strip.Color(alpha, 0, 0)); // Red

// Fill the dots one after the other with a color
void colorSet(uint32_t c) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);;

This guide was first published on Oct 07, 2015. It was last updated on Jun 21, 2024.

This page (Arduino Code) was last updated on Jun 21, 2024.

Text editor powered by tinymce.