Created
January 8, 2019 15:05
-
-
Save andycodes00/e71d2d6feeb0e974843e8abede22f059 to your computer and use it in GitHub Desktop.
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 <FastLED.h> | |
#define NUM_LEDS 23 | |
#define BRIGHTNESS_LEDS 84 // set within 0-100 for max brightnetss | |
//#define MAX_CYCLES 3 | |
#define DATA_PIN 1 // pin the data line is connected to | |
// Define the array of leds | |
CRGB leds[NUM_LEDS]; | |
void setup() { | |
Serial.begin(57600); | |
Serial.println("resetting"); | |
LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS); | |
LEDS.setBrightness(BRIGHTNESS_LEDS); | |
//pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(225); } } // 250 | |
void fadeall2(int fade) { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(fade); } } // 250 | |
bool cycle_0(uint8_t &hue) { | |
uint8_t hue_copy = hue; | |
bool result = false; | |
for(int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = CHSV(hue++, 255, 255); | |
FastLED.show(); | |
fadeall(); | |
delay(40); | |
} | |
if (hue_copy > hue) { | |
// the hue cycled. | |
Serial.print(hue_copy); | |
Serial.print(" "); | |
Serial.println(hue); | |
result = true; | |
} | |
return result; | |
} | |
bool cycle_1(uint8_t &hue) { | |
uint8_t hue_copy = hue; | |
bool result = false; | |
hue = hue + 20; | |
for(int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = CHSV(hue, 255, 255); | |
FastLED.show(); | |
//fadeall(); | |
delay(40); | |
} | |
if (hue_copy > hue) { | |
// the hue cycled. | |
Serial.print(hue_copy); | |
Serial.print(" "); | |
Serial.println(hue); | |
result = true; | |
} | |
return result; | |
} | |
bool cycle_2(uint8_t &hue) { | |
uint8_t hue_copy = hue; | |
bool result = false; | |
hue++; | |
for(int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = CHSV(hue, 255, 255); | |
} | |
FastLED.show(); | |
delay(60); | |
if (hue_copy > hue) { | |
// the hue cycled. | |
Serial.print(hue_copy); | |
Serial.print(" "); | |
Serial.println(hue); | |
result = true; | |
} | |
return result; | |
} | |
bool cycle_3(uint8_t &hue) { | |
uint8_t hue_copy = hue; | |
bool result = false; | |
hue = hue + 30; | |
const size_t n = sizeof(leds) / sizeof(leds[0]); | |
for (size_t i = 0; i < n - 1; i++) | |
{ | |
size_t j = random(0, n - i); | |
leds[j] = CHSV(hue, 255, 255); | |
FastLED.show(); | |
fadeall(); | |
delay(80); | |
} | |
if (hue_copy > hue) { | |
result = true; | |
} | |
return result; | |
} | |
bool cycle_4() { | |
for(int i = 0; i < NUM_LEDS/2; i++) { | |
leds[i] = CRGB(255, 255, 255); | |
leds[i+(NUM_LEDS/2)] = CRGB(255, 255, 255); | |
FastLED.show(); | |
fadeall2(150); | |
delay(80); | |
} | |
} | |
void loop() { | |
// unsigned integer can only hold 255 values. | |
// after 255 it loops back around to 0 | |
static uint8_t hue = 0; | |
static uint8_t cycle = 0; | |
switch (cycle) { | |
case 0: | |
Serial.print("cycle_0 hue:"); | |
Serial.print(hue); | |
Serial.print(" cycle: "); | |
Serial.println(cycle); | |
if (cycle_0(hue)) cycle++; | |
break; | |
case 1: | |
Serial.print("cycle_1 hue:"); | |
Serial.print(hue); | |
Serial.print(" cycle: "); | |
Serial.println(cycle); | |
if (cycle_1(hue)) cycle++; | |
break; | |
case 2: | |
Serial.print("cycle_2 hue:"); | |
Serial.print(hue); | |
Serial.print(" cycle: "); | |
Serial.println(cycle); | |
if (cycle_2(hue)) cycle++; | |
break; | |
case 3: | |
Serial.print("cycle_3 hue:"); | |
Serial.print(hue); | |
Serial.print(" cycle: "); | |
Serial.println(cycle); | |
if (cycle_3(hue)) cycle++; | |
break; | |
case 4: | |
cycle_4(); | |
cycle_4(); | |
cycle_4(); | |
cycle_4(); | |
cycle++; | |
break; | |
default: | |
Serial.println("resetting cycle"); | |
cycle = 0; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment