Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
led arduino
// Map led strips to their pixel values.
// e.g. ledStripRanges[0][1] is the
// pixel range for the bottom strip
// on the right side.
int ledStripRanges[19][2][2] = {
{
{900, 1018}, {600, 715}
},{
{1018, 1135}, {715, 828}
},{
{1135, 1200}, {828, 900}
},{
{538, 600}, {1738, 1800}
},{
{300, 420}, {420, 538}
},{
{0, 89}, {2100, 2190}
},{
{89, 179}, {2190, 2280}
},{
{179, 237}, {2280, 2337}
},{
{237, 300}, {2337, 2400}
},{
{1500, 1560}, {1560, 1620}
},{
{1620, 1680}, {1680, 1738}
},{
{1800, 1860}, {1860, 1920}
},{
{1920, 1980}, {1980, 2038}
},{
{1227, 1257}, {1200, 1227}
},{
{1257, 1285}, {1285, 1315}
},{
{1346, 1372}, {1315, 1346}
},{
{1372, 1395}, {1395, 1423}
},{
{1450, 1480}, {1423, 1450}
},{
{2070, 2100}, {2038, 2070}
}
};
int colors[19][2] = {
{0xE20005, 0xE20005},
{0xE20005, 0xE20005},
{0xF22306, 0xF22306},
{0xFC3607, 0xFC3607},
{0xFD6808, 0xFD6808},
{0xFD7A08, 0xFD7A08},
{0xF7A608, 0xF7A608},
{0xB0DB08, 0xB0DB08},
{0x8FB705, 0x8FB705},
{0x17B42F, 0x17B42F},
{0x17B42F, 0x17B42F},
{0x15A424, 0x15A424},
{0x0F712C, 0x0F712C},
{0x1397E1, 0x1397E1},
{0x1088CE, 0x1088CE},
{0x0E75C9, 0x0E75C9},
{0x0A59A5, 0x0A59A5},
{0x043178, 0x043178},
{0x043178, 0x043178}
};
/* OctoWS2811 Rainbow.ino - Rainbow Shifting Test
http://www.pjrc.com/teensy/td_libs_OctoWS2811.html
Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Required Connections
--------------------
pin 2: LED Strip #1 OctoWS2811 drives 8 LED Strips.
pin 14: LED strip #2 All 8 are the same length.
pin 7: LED strip #3
pin 8: LED strip #4 A 100 ohm resistor should used
pin 6: LED strip #5 between each Teensy pin and the
pin 20: LED strip #6 wire to the LED strip, to minimize
pin 21: LED strip #7 high frequency ringining & noise.
pin 5: LED strip #8
pin 15 & 16 - Connect together, but do not use
pin 4 - Do not use
pin 3 - Do not use as PWM. Normal use is ok.
pin 1 - Output indicating CPU usage, monitor with an oscilloscope,
logic analyzer or even an LED (brighter = CPU busier)
*/
#include <OctoWS2811.h>
const int ledsPerStrip = 300;
DMAMEM int displayMemory[ledsPerStrip*6];
int drawingMemory[ledsPerStrip*6];
const int config = WS2811_GRB | WS2811_800kHz;
OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
void setup() {
Serial.begin(57600);
pinMode(1, OUTPUT);
leds.begin();
digitalWrite(1, HIGH);
for(int y=0; y<2; y++) {
for(int x=0; x < 19; x++) {
int *range = ledStripRanges[x][y];
for(int i=range[0]; i<range[1]; i++) {
leds.setPixel(i, 0);
}
}
}
leds.show();
digitalWrite(1, LOW);
randomSeed(analogRead(0));
}
int count = 0;
int leftHeight = 19, rightHeight = 19;
int leftHeightTemp = 0, rightHeightTemp = 0;
String inData = "", leftString = "", rightString = "";
void loop() {
// leds.setPixel(count, 0xFFFFFF);
while (Serial.available() > 0)
{
char recieved = Serial.read();
inData += recieved;
// Process message when new line character is recieved
if (recieved == '\n')
{
// Serial.println("Arduino Received: ");
// Serial.print(inData);
int commaPosition = inData.indexOf(',');
leftString = inData.substring(0, commaPosition);
rightString = inData.substring(commaPosition+1);
leftHeightTemp = leftString.toInt();
rightHeightTemp = rightString.toInt();
// Serial.println(leftHeightTemp
if(leftHeightTemp == -1 || rightHeightTemp == -1) {
leftHeight = 0;
rightHeight = 0;
wipeDown();
} else {
leftHeight = leftHeightTemp;
rightHeight = rightHeightTemp;
}
inData = ""; // Clear recieved buffer
}
}
// paint(leftHeight, rightHeight);
paint(19, 19);
}
void paint(int highNumX, int highNumY)
{
// Serial.println(highNum);
int count = 0;
int x, y;
int highNums[2] = { highNumX, highNumY };
digitalWrite(1, HIGH);
for(y=0; y<2; y++) {
for(x=highNums[y]; x < 19; x++) {
int *range = ledStripRanges[x][y];
if(range[0] == 0 && range[1] == 0) {
continue;
}
for(int i=range[0]; i<range[1]; i++) {
leds.setPixel(i, 0);
}
}
}
for(y=0; y<2; y++) {
for(x=0; x < highNums[y]; x++) {
int *range = ledStripRanges[x][y];
if(range[0] == 0 && range[1] == 0) {
continue;
}
for(int i=range[0]; i<range[1]; i++) {
leds.setPixel(i, colors[18-x][y]);
}
}
}
leds.show();
digitalWrite(1, LOW);
}
void wipeDown() {
for(int x=18; x >= 0; x--) {
digitalWrite(1, HIGH);
for(int y=0; y<2; y++) {
int *range = ledStripRanges[x][y];
for(int i=range[0]; i<range[1]; i++) {
leds.setPixel(i, 0);
}
}
leds.show();
digitalWrite(1, LOW);
delayMicroseconds(40000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.