From Hive76 Wiki
Revision as of 00:04, 21 March 2017 by Matt (talk | contribs)
Jump to: navigation, search

Presentation slides

Class slides here:

Bill of Materials

Adafruit Metro Mini:
NeoPixel Strip (60 LEDs per meter):

Install the Arduino IDE

Grab the appropriate Arduino software from their website:
Follow the installation instructions for your operating system:

Install the FastLED library

From the Arduino window menu, choose Sketch, Include library, Manage Libraries. Type "fastled" into the search, choose FastLED 3.1.3 and install.

Product link to Metro Mini

Technical details on the Metro Mini microcontroller from Adafruit: Documentation

Available on github:
Color specific information:

Class demo source code

Below, you will find the demo source code for the Hive76 NeoPixel class. Copy and paste this into the Arduino IDE to get started!

#include "FastLED.h"    // Loads FastLED library

#define NUM_LEDS 20     // How many NeoPixels on your strip? 
#define DATA_PIN 3      // Data pin from microcontroller connected to LED strip
#define BUTTON_PIN 4    // Data pin to read button state 
#define BUTTON_GND 6    // Data pin providing ground source to button, since we have limited mounting options for the Metro-Mini
#define KNOB_PIN A0     // analog input pin that is connected to the center pin of potentiometer, where pot position will be measured
#define KNOB_GND A1     // analog input pin that is connected to one side of potentiometer, and will be needed to supply ground

int buttonPressed = 1;  // initial state of push button, since input is pulled high and we need to declare variable scope. 

CRGB leds[NUM_LEDS];    // Tells the Library how many pixels we have

void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL,DATA_PIN>(leds, NUM_LEDS); // this specifies the configuration for the FastLED library
  pinMode(KNOB_GND, OUTPUT);                          // configures Analog pin to be an output...
  digitalWrite(KNOB_GND, LOW);                        // ...and writes a zero/low, to supply ground to the potentiometer
  pinMode(BUTTON_PIN, INPUT_PULLUP);                  // configures the digital pin for the button to be an input, and enable the internal pullup resistor
  pinMode(BUTTON_GND, OUTPUT);                        // configures the digital pin for the button ground to be an output...
  digitalWrite(BUTTON_GND, LOW);                      // ...and writes a zero/low, to supply ground to the button

void loop() {
  // put your main code here, to run repeatedly:
  int val = analogRead(KNOB_PIN);                 // reads the analog voltage of the potentiometer
  int colorOfLed = map(val, 0, 1023, 0, 255);     // this map function takes the 10-bit value read from potentiometer and converts to 8-bit value that can be used for the hue

  leds[0].setHSV( colorOfLed, 255, 200);          // sets the first NeoPixel to the hue of the potentiometer, with full color saturation and 200 brightness;                                 // sends the above data to the NeoPixels

  buttonPressed = digitalRead(BUTTON_PIN);        // read and store button state
  if (buttonPressed == LOW) {                     // logic check if button is currently pressed
    for (int i = 1; i < NUM_LEDS; i++) {          // this for loop starts at second pixel (1), then increments pixels until until it reachs the last LED on the strip
      leds[i] = CHSV( colorOfLed, 255, 200);      // sets the incremented pixel to the hue set by pot, full color saturation, 200 brightness;                             // writes data to the NeoPixels
      leds[i-1] = CRGB::Black;                    // blanks out the previous pixel;                             // writes data to the NeoPixels
      FastLED.delay(15);                          // delays 15ms between movement of each pixel
    FastLED.clear();                              // turns off the pixels, and writes immediately, when the pixel animation loop above completes