Skip to content

Instantly share code, notes, and snippets.

@copyfun
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save copyfun/3b37892fdfbec1fa0272 to your computer and use it in GitHub Desktop.
Save copyfun/3b37892fdfbec1fa0272 to your computer and use it in GitHub Desktop.
neopixel + attiny85 + cr1220 = little LED rainbow ring!
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// choose your pin from 0 - 4
#define PIN 4
// I have only ONE neopixel in this ring and it's v2.
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// won't work without this line.
clock_prescale_set(clock_div_2);
strip.begin();
strip.show();
}
void loop() { rainbowCycle(10); }
// copy from strandtest
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
// copy from strandtest
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment