Skip to content

Instantly share code, notes, and snippets.

@stlk
Created November 13, 2016 08:09
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 stlk/5cb497f88d867cc05852a73a65712f74 to your computer and use it in GitHub Desktop.
Save stlk/5cb497f88d867cc05852a73a65712f74 to your computer and use it in GitHub Desktop.
#include <Adafruit_NeoPixel.h>
#define PIN 1
#define WAIT 40
// pouzivame knihovnu Adafruit_NeoPixel pro komunikaci s diodou
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Zakladni nastaveni diody
strip.begin();
strip.setBrightness(255);
}
void loop() {
for(uint16_t j = 0; j < 256; j++) { // cyklus od 0 do 255, ktery postupne meni barvy
strip.setPixelColor(0, vypocet_barvy(j)); // zjisti barvu pomoci funkce vypocet_barvy a nastavi ji do diody
strip.show(); // rekne diode aby ukazala barvu
delay(WAIT); // cekani 40 milisekund
}
}
// tohle je nejaka vec, ktera pocita barvu :)
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t vypocet_barvy(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