Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define USE_WS2812SERIAL
- #define USE_OCTOWS2811
- //#include <WS2812Serial.h>
- #include <OctoWS2811.h>
- #include <OneButton.h>
- #include <FastLED.h>
- #define NUM_LEDS 80
- #define DATA_PIN 1
- //#define LED_TYPE WS2812B
- //#define LED_TYPE WS2812SERIAL
- #define LED_TYPE OCTOWS2811
- #define ORDER GRB
- #define BRIGHTNESS 128
- #define SATURATION 255
- #define BUTTON_PIN 3
- #define NUM_ANIMATION 18
- #define FORWARD 0
- #define BACKWARD 1
- #define SLOW 250
- #define MEDIUM 50
- #define FAST 5
- volatile int animation = 18;
- int oldAnimation = animation;
- CRGB leds[NUM_LEDS];
- OneButton button = OneButton(BUTTON_PIN, true, true);
- void setup() {
- randomSeed(analogRead(0));
- button.attachClick(button_handler);
- //FastLED.addLeds<1, LED_TYPE, DATA_PIN, ORDER>(leds, NUM_LEDS);
- //FastLED.addLeds<LED_TYPE, DATA_PIN, ORDER>(leds, NUM_LEDS);
- FastLED.addLeds<LED_TYPE, ORDER>(leds, NUM_LEDS);
- Serial.begin(9600);
- delay(1000);
- }
- void button_handler() {
- animation < NUM_ANIMATION ? animation++ : animation = 1;
- //animation < 5 ? animation++ : animation = 1;
- }
- void loop() {
- button.tick();
- EVERY_N_SECONDS( 2 ) {
- animation < NUM_ANIMATION ? animation++ : animation = 1;
- }
- oldAnimation = animation;
- switch (animation) {
- case 1:
- white();
- break;
- case 2:
- colorWipe(CHSV(0, 0, 0), FAST, BACKWARD);
- break;
- case 3:
- hue(0, SATURATION);
- break;
- case 4:
- colorWipe(CHSV(0, 0, 0), FAST, FORWARD);
- break;
- case 5:
- rainbow(MEDIUM);
- break;
- case 6:
- point(MEDIUM);
- break;
- case 7:
- allRandom(MEDIUM);
- break;
- case 8:
- disolve(15, 100, MEDIUM);
- break;
- case 9:
- lightning(CHSV(0, 0, BRIGHTNESS), 20, 50, MEDIUM);
- break;
- case 10:
- lightning(15, 50, MEDIUM);
- break;
- case 11:
- flash(CHSV(random(256), SATURATION, BRIGHTNESS), 10, SLOW);
- break;
- case 12:
- flash(50, MEDIUM);
- break;
- case 13:
- for (int i = 0; i < 2; i++){
- cylon(CHSV(random(256), SATURATION, BRIGHTNESS), 10,FAST);
- }
- break;
- case 14:
- for (int i = 0; i < 3 && oldAnimation == animation; i++){
- button.tick();
- theaterChase(CHSV(random(256), SATURATION, BRIGHTNESS),10,SLOW);
- }
- break;
- case 15:
- for (int i = 0; i < 3 && oldAnimation == animation; i++) {
- button.tick();
- CHSV c1 = CHSV(random(256), SATURATION, BRIGHTNESS);
- CHSV c2 = CHSV(random(256), SATURATION, BRIGHTNESS);
- stripes(c1,c2,5);
- delayForMillis(2000);
- button.tick();
- stripes(c2,c1,5);
- delayForMillis(2000);
- button.tick();
- }
- break;
- case 16:
- theaterChaseRainbow(1,MEDIUM);
- break;
- case 17:
- black();
- break;
- case 18:
- test();
- break;
- }
- }
- void delayForMillis(unsigned long time) {
- unsigned long start = millis();
- do {
- button.tick();
- } while (millis() - start < time);
- }
- void test() {
- button.tick();
- leds[0] = CHSV(0, SATURATION, BRIGHTNESS);
- leds[1] = CHSV(96, SATURATION, BRIGHTNESS);
- leds[2] = CHSV(160, SATURATION, BRIGHTNESS);
- FastLED.show();
- }
- void black() {
- hue(CHSV(0, 0, 0));
- }
- void white () {
- hue(0, 0);
- }
- void hue (CHSV hue) {
- for (int i = 0; i < NUM_LEDS && oldAnimation == animation; i++) {
- button.tick();
- leds[i] = hue;
- }
- FastLED.show();
- }
- void hue (int hue, int saturation) {
- /*for (int i = 0; i < NUM_LEDS && oldAnimation == animation; i++) {
- button.tick();
- leds[i] = CHSV(hue, saturation, BRIGHTNESS);
- }*/
- button.tick();
- fill_solid(leds, NUM_LEDS, CHSV(hue, saturation, BRIGHTNESS));
- FastLED.show();
- }
- void rainbow (int speed) {
- for (int j = 0; j < 255 && oldAnimation == animation; j++) {
- button.tick();
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CHSV(i - (j * 2), SATURATION, BRIGHTNESS);
- }
- FastLED.show();
- delayForMillis(speed);
- }
- }
- void point (int speed ) {
- for (int led = 0; led < NUM_LEDS && oldAnimation == animation; led++) {
- button.tick();
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CHSV(0, 0, 0);
- }
- leds[led] = CHSV(0, 0, BRIGHTNESS);
- FastLED.show();
- delayForMillis(speed);
- }
- }
- void allRandom (int speed){
- for(int i = 0; i < NUM_LEDS && oldAnimation == animation; i++){
- button.tick();
- leds[i] = CHSV(random(256), SATURATION, BRIGHTNESS);
- }
- FastLED.show();
- delayForMillis(speed);
- }
- void disolve (int simultaneous, int cycles, int speed) {
- for (int i = 0; i < cycles && oldAnimation == animation; i++) {
- button.tick();
- for (int j = 0; j < simultaneous; j++){
- int idx = random(NUM_LEDS);
- leds[idx] = CHSV(0, 0, 0);
- }
- FastLED.show();
- delayForMillis(speed);
- }
- black();
- }
- void colorWipe (CHSV c, int speed, int direction) {
- for (int i = 0; i < NUM_LEDS && oldAnimation == animation; i++) {
- button.tick();
- if(direction == FORWARD) {
- leds[i] = c;
- } else {
- leds[NUM_LEDS-1-i] = c;
- }
- FastLED.show();
- delayForMillis(speed);
- }
- }
- void lightning (CHSV c, int simultaneous, int cycles, int speed) {
- int flashes[simultaneous];
- for (int i = 0; i < cycles && oldAnimation == animation; i++) {
- button.tick();
- for (int j = 0; j < simultaneous; j++) {
- int idx = random(NUM_LEDS);
- flashes[j] = idx;
- leds[idx] = c;
- }
- FastLED.show();
- delayForMillis(speed);
- for (int s = 0; s < simultaneous; s++){
- leds[flashes[s]] = CHSV(0, 0, 0);
- }
- delayForMillis(speed);
- }
- }
- void lightning (int simultaneous, int cycles, int speed) {
- int flashes[simultaneous];
- for (int i = 0; i < cycles && oldAnimation == animation; i++) {
- button.tick();
- for (int j = 0; j < simultaneous; j++) {
- int idx = random(NUM_LEDS);
- flashes[j] = idx;
- leds[idx] = CHSV(random(256), SATURATION, BRIGHTNESS);
- }
- FastLED.show();
- delayForMillis(speed);
- for (int s = 0; s < simultaneous; s++) {
- leds[flashes[s]] = CHSV(0, 0, 0);
- }
- delayForMillis(speed);
- }
- }
- void flash (CHSV c, int count, int speed) {
- for (int i = 0; i < count && oldAnimation == animation; i++) {
- button.tick();
- hue(c);
- delayForMillis(speed);
- black();
- delayForMillis(speed);
- }
- }
- void flash (int count, int speed) {
- for (int i = 0; i < count && oldAnimation == animation; i++) {
- button.tick();
- hue(CHSV(random(256), SATURATION, BRIGHTNESS));
- delayForMillis(speed);
- black();
- delayForMillis(speed);
- }
- }
- void cylon (CHSV c, int width, int speed) {
- // First slide the leds in one direction
- for (int i = 0; i <= NUM_LEDS-width && oldAnimation == animation; i++) {
- button.tick();
- for (int j = 0; j < width; j++) {
- leds[i+j] = c;
- }
- FastLED.show();
- for (int j = 0; j < 5; j++) {
- leds[i+j] = CHSV(0, 0, 0);
- }
- delayForMillis(speed);
- }
- for(int i = NUM_LEDS-width; i >= 0 && oldAnimation == animation; i--) {
- button.tick();
- for (int j = 0; j < width; j++) {
- leds[i+j] = c;
- }
- FastLED.show();
- for (int j = 0; j < width; j++) {
- leds[i+j] = CHSV(0, 0, 0);
- }
- delayForMillis(speed);
- }
- }
- void theaterChase (CHSV c, int cycles, int speed) {
- for (int j = 0; j < cycles && oldAnimation == animation; j++) {
- for (int q = 0; q < 3; q++) {
- button.tick();
- for (int i = 0; i < NUM_LEDS; i = i + 3) {
- int pos = i + q;
- leds[pos] = c; //turn every third pixel on
- }
- FastLED.show();
- delayForMillis(speed);
- for (int i = 0; i < NUM_LEDS; i = i + 3) {
- button.tick();
- leds[i + q] = CHSV(0, 0, 0); //turn every third pixel off
- }
- }
- }
- }
- void stripes(CHSV c1, CHSV c2, int width){
- for(int i=0; i<NUM_LEDS && oldAnimation == animation; i++){
- button.tick();
- if(i % (width * 2) < width){
- leds[i] = c1;
- }
- else{
- leds[i] = c2;
- }
- }
- FastLED.show();
- }
- void theaterChaseRainbow (int cycles, int speed) {
- for (int j = 0; j < 256 * cycles && oldAnimation == animation; j++) {
- for (int q = 0; q < 3; q++) {
- for (int i = 0; i < NUM_LEDS; i = i + 3) {
- button.tick();
- int pos = i + q;
- leds[pos] = CHSV((i + j) % 255, SATURATION, BRIGHTNESS);
- }
- FastLED.show();
- delayForMillis(speed);
- for (int i = 0; i < NUM_LEDS; i = i + 3) {
- button.tick();
- leds[i + q] = CHSV(0, 0, 0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement