Last active
January 3, 2016 22:39
-
-
Save RonjaPonja/8529801 to your computer and use it in GitHub Desktop.
Pretty LED stuff.
This file contains hidden or 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
#include <Adafruit_NeoPixel.h> | |
#define PIN 6 | |
#define NumberPixels 60 | |
#define FadeFrames 6 | |
// 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(NumberPixels, PIN, NEO_GRB + NEO_KHZ800); | |
uint32_t coloursOld[ NumberPixels ][3]; | |
uint32_t coloursNew[ NumberPixels ][3]; | |
void setup() { | |
strip.begin(); | |
strip.setBrightness(100); | |
strip.show(); // Initialize all pixels to 'off' | |
} | |
void loop() { | |
crowdForever(); | |
} | |
void randomSet(uint32_t colours[][3]) { // I am stupid and don't know pointers.. | |
for(uint32_t ledNr=0;ledNr<strip.numPixels();ledNr++) | |
{ | |
colours[ledNr][0] = random(256); | |
colours[ledNr][1] = random(256); | |
colours[ledNr][2] = 20; | |
} | |
return; | |
} | |
void fade() { | |
uint32_t rgbTriplet[3]; | |
for (uint32_t Frame = 1; Frame <= FadeFrames; ++Frame ) { | |
for (uint32_t ledNr=0; ledNr < strip.numPixels(); ledNr++ ) { | |
for (uint32_t rgb = 0; rgb < 3; ++rgb ) { | |
rgbTriplet[rgb] = coloursOld[ledNr][rgb] + (int)(((float)coloursNew[ledNr][rgb] - (float)coloursOld[ledNr][rgb]) / (float)FadeFrames * (float)Frame); | |
} | |
strip.setPixelColor(ledNr, rgbTriplet[0], rgbTriplet[1], rgbTriplet[2]); | |
} | |
delay(0); | |
strip.show(); | |
} | |
} | |
void crowdForever() { | |
randomSeed(analogRead(0)); | |
randomSet(coloursNew); | |
while (true) { | |
delay(0); | |
memcpy ( coloursOld, coloursNew, sizeof(uint32_t) * NumberPixels * 3); | |
randomSet(coloursNew); | |
fade(); | |
} | |
} |
This file contains hidden or 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
Bauteile: | |
- USB A-Stecker | |
Nur zur Stromversorgung | |
Bitte _nicht_ in ein Laptop/Computer stecken. Diese liefern nicht genügend Strom. | |
- USB-Netzteil - 5V, 1 Amper | |
- Lichterkette - RGB - jede LED einzelnd ansteuerbar | |
http://www.aliexpress.com/item/12mm-UCS1903-WS2811-similar-to-WS2801-pixel-module-IP65-IP68-waterproof-DC5V-full-color-50pcs-a/1311369342.html | |
- Arduino UNO - Mikrocontroller - programmiert in C++ | |
http://www.amazon.de/Arduino-Uno-Board-REV-3/dp/B006H06TVG/ref=sr_1_2?ie=UTF8&qid=1393866523&sr=8-2&keywords=arduino+uno | |
Code: https://gist.github.com/spaceSub/8529801 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment