Plug in a USB cable to connect the FLORA main board to your computer. Open up the Adafruit Arduino IDE, which you can download from the Getting Started with FLORA guide.

First test out your pixel's connections by uploading the sketch in File >> Examples >> Adafruit_NeoPixel >> strandtest.

Then upload the code below to make the pixel change color when the snap is connected/disconnected:

Download: file
#include <Adafruit_NeoPixel.h>

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, 6, NEO_GRB + NEO_KHZ800);
const int buttonPin = 1;     // the fin snap is connected to FLORA TX, the other half of the snap is conntected to GND
int buttonState = 0;         // variable for reading the snap status

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
    // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH);
}

void loop() {
    // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  
    // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) {     
    // turn LED on:    
    strip.setPixelColor(0, strip.Color(200, 211, 254)); // color when snap is connected
  strip.show();  
  } 
  else {
    // change LED color
    strip.setPixelColor(0, strip.Color(250, 0, 0)); // color when snap is disconnected
  strip.show(); 
  }
  
    delay(50);
}

You an adapt this project for Gemma by changing the button pin to be Digital #0 or #2 and the NeoPixels on Digital #1 - the code will also need adjustments for the new pin connections

This guide was first published on May 08, 2013. It was last updated on May 08, 2013.

This page (Code) was last updated on Nov 09, 2020.