Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EEPROM.h>
- #include "FastLED.h"
- #define BUTTON_PIN 3
- #define LED_PIN 6
- #define NUM_LEDS 80
- #define RING_SIZE 5 // Leds on the horizontal plane
- #define MODE_ADDRESS 0 // Address to store current lamp mode in
- #define SPIRAL_COUNT NUM_LEDS/RING_SIZE // Leds on the vertical plane
- bool buttonState;
- bool lastButtonState = LOW;
- unsigned long lastDebounceTime = 0;
- unsigned long debounceDelay = 1;
- /*
- 'mode' holds the current lamp mode.
- 0: Solid white
- 1: Breathing red
- 2: Breathing green
- 3: Breathing blue
- 4: Rainbow
- 5: Move to music
- 6: Spiral
- 7: Ring
- 8: Fire (Red > Orange)
- 9: Fire2 (Blue > Cyan)
- 10: Sombra
- 11: Rave
- */
- int mode; // Current mode
- int modes = 12; // Maximum modes
- // Array of all the LEDS
- CRGB leds[NUM_LEDS];
- void setup() {
- // Initialize LED strip
- FastLED.addLeds<WS2811, LED_PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000);
- // Initialize button
- pinMode(BUTTON_PIN, INPUT);
- // Read memory for current address
- EEPROM.get(MODE_ADDRESS, mode);
- }
- void loop() {
- // Get button input
- int reading = digitalRead(BUTTON_PIN);
- // If the switch changed, due to noise or pressing:
- if (reading != lastButtonState) {
- // reset the debouncing timer
- lastDebounceTime = millis();
- }
- // Account for debouncing
- if ((millis() - lastDebounceTime) > debounceDelay) {
- // if the button state has changed:
- if (reading != buttonState) {
- buttonState = reading;
- // Increment state when button is pressed
- if (buttonState == HIGH) {
- mode++;
- // Loop around if we have hit the last state
- if (mode == modes) {
- mode = 0;
- }
- // Save the mode to memory
- EEPROM.put(MODE_ADDRESS, mode);
- }
- }
- }
- // Save the reading.,
- lastButtonState = reading;
- // Default brightness to 255, effects may change this
- FastLED.setBrightness(255);
- // Reset all leds
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- // Choose effect depending on 'state'
- switch(mode) {
- case 0:
- solidWhite(); break;
- case 1:
- breathingRed(); break;
- case 2:
- breathingGreen(); break;
- case 3:
- breathingBlue(); break;
- case 4:
- rainbow(); break;
- case 5:
- music(); break;
- case 6:
- spiral(); break;
- case 7:
- ring(); break;
- case 8:
- fire(); break;
- case 9:
- fire2(); break;
- case 10:
- sombra(); break;
- case 11:
- rave(); break;
- default:
- break;
- }
- // Display LEDS
- LEDS.show();
- }
- void solidWhite() {
- fill_solid(leds, NUM_LEDS, CRGB::White);
- }
- void breathingRed() {
- static float breathingSpeed = 5000.0f;
- static int minBrightness = 40;
- static int maxBrightness = 255;
- fill_solid(leds, NUM_LEDS, CRGB::Red);
- float breath = (exp(sin(millis()/breathingSpeed*PI)) - 0.36787944)*108.0;
- FastLED.setBrightness(map(breath, 0, 255, minBrightness, maxBrightness));
- }
- void breathingGreen() {
- static float breathingSpeed = 5000.0f;
- static int minBrightness = 40;
- static int maxBrightness = 255;
- fill_solid(leds, NUM_LEDS, CRGB::Green);
- float breath = (exp(sin(millis()/breathingSpeed*PI)) - 0.36787944)*108.0;
- FastLED.setBrightness(map(breath, 0, 255, minBrightness, maxBrightness));
- }
- void breathingBlue() {
- static float breathingSpeed = 5000.0f;
- static int minBrightness = 40;
- static int maxBrightness = 255;
- fill_solid(leds, NUM_LEDS, CRGB::Blue);
- float breath = (exp(sin(millis()/breathingSpeed*PI)) - 0.36787944)*108.0;
- FastLED.setBrightness(map(breath, 0, 255, minBrightness, maxBrightness));
- }
- void rainbow() {
- static float movingSpeed = 0.2f;
- static float offset = 0;
- static float delta = 2.0f;
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i].setHSV(offset + (i * delta), 255, 255);
- }
- offset += movingSpeed;
- }
- void music() {
- }
- void spiral() {
- static CRGB primaryColor = CRGB::Green;
- static CRGB secondaryColor = CRGB::Cyan;
- static int tailLength = 12;
- static int waitTime = 50;
- static int spiral = 0;
- static int pos = 0;
- fill_solid(leds, NUM_LEDS, primaryColor);
- for (int i = pos; i > pos-tailLength; i--) {
- int realPos = (i * 5) + spiral;
- if (realPos > -1) {
- leds[realPos] = secondaryColor;
- }
- }
- if (pos == 15 + tailLength) {
- pos = 0;
- spiral = spiral + 1;
- }
- pos++;
- delay(waitTime);
- }
- void ring() {
- static CRGB primaryColor = CRGB::Green;
- static CRGB secondaryColor = CRGB::Cyan;
- static int waitTime = 100;
- static int pos = 0;
- static int dir = 1;
- fill_solid(leds, NUM_LEDS, primaryColor);
- for (int i = 0; i < 5; i++) {
- int realPos = (pos * 5) + i;
- leds[realPos] = secondaryColor;
- }
- if (pos == 0) {
- dir = 1;
- }
- if (pos == 15) {
- dir = -1;
- }
- pos += dir;
- delay(waitTime);
- }
- void fire() {
- static CHSV primaryColor = CHSV(0, 255, 255);
- static CHSV secondaryColor = CHSV(50, 255, 150);
- static float flickerTime = 60.0f;
- static int intensity = 3;
- static int endPos = 40;
- static int minPos = 5;
- static int maxPos = NUM_LEDS;
- endPos += random(-1, 2) * intensity;
- if (endPos <= minPos) {
- endPos = minPos;
- } else if (endPos >= maxPos) {
- endPos = maxPos;
- }
- fill_gradient(leds, 0, primaryColor, endPos, secondaryColor, SHORTEST_HUES);
- delay(flickerTime);
- }
- void fire2() {
- static CHSV primaryColor = CHSV(150, 255, 255);
- static CHSV secondaryColor = CHSV(110, 255, 255);
- static float flickerTime = 60.0f;
- static int intensity = 3;
- static int endPos = 40;
- static int minPos = 5;
- static int maxPos = NUM_LEDS;
- endPos += random(-1, 2) * intensity;
- if (endPos <= minPos) {
- endPos = minPos;
- } else if (endPos >= maxPos) {
- endPos = maxPos;
- }
- fill_gradient(leds, 0, primaryColor, endPos, secondaryColor, SHORTEST_HUES);
- delay(flickerTime);
- }
- void sombra() {
- static CRGB primaryColor = CHSV(210, 255, 255);
- static CHSV secondaryColor = CHSV(210, 140, 140);
- static int pos = 0;
- static int tailLength = 50;
- static float waitTime = 30.0f;
- fill_solid(leds, NUM_LEDS, secondaryColor);
- for (int i = 0; i < tailLength; i++) {
- int realPos = pos + i;
- if (realPos >= 0 && realPos <= NUM_LEDS) {
- leds[pos + i] = primaryColor;
- }
- }
- if (pos > NUM_LEDS) {
- pos = -tailLength;
- }
- pos++;
- delay(waitTime);
- }
- void rave() {
- static float waitTime = 150.0f;
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i].setRGB(random(30, 176), random(30, 176), random(30, 176));
- }
- delay(waitTime);
- }
Add Comment
Please, Sign In to add comment