Skip to content

Instantly share code, notes, and snippets.

@brainrake
Created January 1, 2014 04:58
Show Gist options
  • Save brainrake/8205249 to your computer and use it in GitHub Desktop.
Save brainrake/8205249 to your computer and use it in GitHub Desktop.
led strand test
#include <Wire.h>
#include "WiiChuck.h"
#include <Adafruit_NeoPixel.h>
#define PIN 0
//#define N 232
#define N 62
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N, PIN, NEO_GRB + NEO_KHZ800);
WiiChuck chuck = WiiChuck();
void setup() {
delay(3000);
Serial.begin(115200);
Serial.print("serial\n");
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Serial.print("strip\n");
//chuck.begin();
//chuck.update();
Serial.print("chuck\n");
}
uint32_t L = 5;
#define IDLE 0
#define XPOS 1
uint32_t state = IDLE;
uint32_t idle = 0;
uint32_t fire = 0;
uint32_t i = 0;
uint32_t T = 0;
uint32_t d = 0;
boolean up = true;
void loop() {
T++;
for (uint32_t j=0; j<N; j++) { strip.setPixelColor(j, strip.Color(0,0,0)); }
if (state == IDLE) {
if (T % 8) {
d++;
}
for (uint32_t j=0; j<L; j++) {
strip.setPixelColor(j+i, Wheel(((j+i)*255/N + d)*2 & 255));
if (j+i > N) {
strip.setPixelColor(j+i-N-1, Wheel(((j+i)*255/N + d)*2 & 255));
}
}
/*
if ((abs(chuck.readJoyX()) > 50)) {
state = XPOS;
}
*/
if (T%4) {
//if (up) { i++; } else {i--;}
//if (i == N+L+2) {up = false;}
//if (i == 0-L-2) {up = true;}
i++;
if(i >= N) {i = 0;}
}
}
strip.show();
delay(20);
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment