Skip to content

Instantly share code, notes, and snippets.

@jaretburkett
Last active April 12, 2016 01:56
Show Gist options
  • Save jaretburkett/153fadb0c15f131d1b35edf898b52e8d to your computer and use it in GitHub Desktop.
Save jaretburkett/153fadb0c15f131d1b35edf898b52e8d to your computer and use it in GitHub Desktop.
#include "TimerOne.h"
#include <Adafruit_NeoPixel.h>
#define PIN 6 // neopixel pin
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 16
bool pixOn = false; //holds current value of pixels
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
pixels.begin(); // This initializes the NeoPixel library.
// setup timer interrupt
Timer1.initialize(33333); // initialize timer1, and set period in microseconds (1,000,000 (1 sec) / 30 = ~33,333
Timer1.attachInterrupt(neopixelFunc); // attaches neopixelFunc() as a timer overflow interrupt
}
// this will run 33 times a second.
void neopixelFunc()
{
// neopixel code here
for(int i=0;i<NUMPIXELS;i++){
if(pixOn){
// pixels are on, turn them off
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
} else {
// pixels are off, turn them on
pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
}
pixels.show(); // This sends the updated pixel color to the hardware.
}
// switch state of pixel value
pixOn = !pixOn;
}
void loop()
{
// your program here...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment