Skip to content

Instantly share code, notes, and snippets.

@pajowu
Created December 28, 2016 17:54
Show Gist options
  • Save pajowu/d449ed3c657b7cf84c1345bcc942ed82 to your computer and use it in GitHub Desktop.
Save pajowu/d449ed3c657b7cf84c1345bcc942ed82 to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
#define PIN 2
#define LED_COUNT 169
#define C_MAX 50
#define DIV 100
#define DELAY 5
int r = 0; //random(0,DIV);
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_RGB + NEO_KHZ800);
int delayval = 1; // delay for half a second
void setup() {
pixels.begin(); // This initializes the NeoPixel library.
pixels.setBrightness(C_MAX);
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 1280; j++) { // 5 cycles of all colors on wheel
for (i = 0; i < pixels.numPixels(); i++) {
int x = (i % 26);
int y = int(i / 13) + 1;
if (x > 12) {
x = 25 - x;
}
x-=5;
y-=5;
float step = 1. / 196;
int u = int(x*y*step*255 + (j*2.5))%255;
pixels.setPixelColor(i, Wheel(u));
}
pixels.show();
delay(wait);
}
}
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
void loop() {
rainbowCycle(DELAY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment