Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define NUM_LEDS 5
- #define DATA_PIN 3
- int hue = 128;
- int saturation = 255;
- int brightness = 255;
- int cosBright[] = { 250, 248, 243, 236, 226, 213, 198, 181, 163, 144, 125, 105, 86, 68, 51, 36, 23, 13, 6, 1, 0, 1, 6, 13, 23, 36, 51, 68, 86, 105, 125, 144, 163, 181, 198, 213, 226, 236, 243, 248 };
- unsigned long updateTime = 25;
- unsigned long partyTime = 520;
- unsigned long startTime = 0;
- unsigned long timeoutTime = 5000000;
- unsigned long clickDuration;
- int state = 1;
- int index = 0;
- int stufe = 0;
- CRGB leds[NUM_LEDS];
- void setup() {
- FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
- pinMode(4, INPUT);
- }
- void loop() {
- switch (state) {
- case 1:
- saturation = 255;
- brightness = 255;
- if (millis() - startTime > updateTime) {
- for (int dot = 0; dot < NUM_LEDS; dot++) {
- leds[dot].setHSV( hue, saturation, brightness);
- }
- startTime = millis();
- }
- FastLED.show();
- clickDuration = pulseIn(4, HIGH, timeoutTime);
- if (clickDuration > 10 && clickDuration < 1000000) {
- clickDuration = pulseIn(4, HIGH, 300000);
- if (clickDuration > 50000 && clickDuration < 200000) {
- state = 3;
- }
- else {
- hue = hue + 16;
- hue = hue % 256;
- }
- }
- else if (clickDuration >= 1000000) {
- state = 2;
- }
- break;
- case 2:
- while (digitalRead(4) == LOW) {
- saturation = 255;
- brightness = cosBright[index];
- constrain(brightness, 10, 255);
- index++;
- index = index % 40;
- hue = hue + 1;
- hue = hue % 256;
- for (int dot = 0; dot < NUM_LEDS; dot++) {
- leds[dot].setHSV( (hue + (dot * 60)), 255, brightness);
- }
- FastLED.show();
- delay(partyTime / 40); //geht schöner
- }
- state = 1;
- break;
- case 3:
- brightness = (64 * (stufe + 1)) - 1;
- saturation = 0;
- if (millis() - startTime > updateTime) {
- for (int dot = 0; dot < NUM_LEDS; dot++) {
- leds[dot].setHSV( hue, saturation, brightness);
- }
- startTime = millis();
- }
- FastLED.show();
- clickDuration = pulseIn(4, HIGH, timeoutTime);
- if (clickDuration > 10 && clickDuration < 1000000) {
- clickDuration = pulseIn(4, HIGH, 300000);
- if (clickDuration > 50000 && clickDuration < 200000) {
- state = 1;
- stufe = 0;
- }
- else {
- stufe = stufe + 1;
- stufe = stufe % 4;
- }
- }
- else if (clickDuration >= 1000000) {
- state = 2;
- }
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement