Created
February 12, 2014 05:43
-
-
Save stevenpetryk/8950590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// :::::::::::::::::::::::: LICENSE AND COPYRIGHT NOTICE ::::::::::::::::::::::: | |
// Copyright (c) 2013 Andrew Hamon. All rights reserved. | |
// | |
// This file is part of FFT-LED-Visualization. FFT-LED-Visualization is | |
// distributed under the MIT License. You can read the full terms of use in the | |
// LICENSE file, or online at http://opensource.org/licenses/MIT. | |
// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
#include <Adafruit_NeoPixel.h> | |
#define stripLength 32 | |
#define ledStripPin 6 | |
// Initialize LED strip | |
Adafruit_NeoPixel myStrip = Adafruit_NeoPixel(stripLength, ledStripPin, | |
NEO_GRB + NEO_KHZ800); | |
byte n; | |
byte k; | |
byte colors[3]; | |
boolean pinOn = false; | |
void setup(){ | |
Serial.begin(115200); | |
pinMode(13, OUTPUT); | |
n = 0; | |
k = 0; | |
myStrip.begin(); | |
myStrip.show(); | |
} | |
void serialEvent(){ | |
while(Serial.available()){ | |
pinOn = !pinOn; | |
byte x = Serial.read(); | |
// If end-of-frame code recieved | |
if(n > 10){ | |
// myStrip.setBrightness(64); //The LEDs are quite bright | |
myStrip.show(); | |
// Reset counters | |
k = 0; | |
n = 0; | |
digitalWrite(13, HIGH); | |
delay(1000); | |
digitalWrite(13, LOW); | |
} | |
else{ | |
// Data is sent R,G,B,R,G,B etc so we must | |
// accumulate and entire RGB triplet before | |
// writing to the LED strip | |
colors[k] = x; | |
k+= 1; | |
if(k > 2){ | |
myStrip.setPixelColor(n, colors[0], colors[1], colors[2]); | |
k = 0; | |
n += 1; | |
} | |
} | |
} | |
} | |
void loop(){ | |
if(pinOn){ | |
digitalWrite(13, HIGH); | |
} | |
else{ | |
digitalWrite(13, LOW); | |
} | |
// Empty loop because sketch is entirely serial event driven | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment