Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////
- ///////// LED SCOOTER BURNING MAN 2015 w/ ENCODER /////////
- ///////////////////////////////////////////////////////////
- // a bit updated by Gyro Gearloose to make the Rotary enconder work
- //INCLUDE LIBRARIES////////////////////////////////////////
- #include <FastLED.h> //Include FastLED Library
- //#include <Encoder.h> //Include Rotary Encoder Library
- // Gyro: you don't need Encoder.h
- //#include <AdaEncoder.h> //Include Ada Encoder Library *TEST*
- //#include <Bounce2.h> //Include Bounce Library *TEST*
- //LED SETUP////////////////////////////////////////////////
- #define LED_PIN 6 //LED Strip Data Pin
- #define CLOCK_PIN 8
- #define LED_TYPE WS2811 //LED Type
- #define COLOR_ORDER GRB //LED Color Order
- #define NUM_LEDS 42 //Number of LEDs
- CRGB leds[NUM_LEDS]; //Name of LED Array
- CRGBPalette16 currentPalette; //Color Palette
- TBlendType currentBlending; //Color Blending
- //PINs for connection of the rotary////////////////////////
- //#define BUTTON_PIN 4 //Button Pin from Rotary Encoder
- #define encoderPinA 2 //Encoder A
- #define encoderPinB 3 //Encoder B
- volatile int encoderPos = 0; // also negative values
- byte count = 0;
- byte lastCount = 0;
- //Bounce debouncer = Bounce();
- //Bounce encoderPos = Bounce( encoderPinA,encoderPinB );
- //#define encoderSwitchPin 4 //Encoder Switch Pin *ALT*
- //Encoder myEnc(3, 5); //Encoder Pins *ALT*
- //BUTTON SETUP/////////////////////////////////////////////
- //byte prevKeyState = HIGH;
- //MODE VARIABLES///////////////////////////////////////////
- int ledMode = 0; //FIRST ACTIVE MODE
- int BRIGHTNESS = 255; //0-255. Lower number saves battery life, higher number is screamingly bright
- int SATURATION = 255; //0 is white (no color) and 255 is fully saturated with color
- int HUE = 0; //0-255, around the color wheel
- int STEPS = 4; //Wider or narrower bands of color
- int SPEEDO = 10; //The speed of the animation
- //SETUP////////////////////////////////////////////////////
- void setup() {
- delay( 2000 ); // power-up safety delay
- // pinMode(BUTTON_PIN, INPUT);
- pinMode(encoderPinA, INPUT);
- pinMode(encoderPinB, INPUT);
- digitalWrite(encoderPinA, HIGH); // use internal pull-ups
- digitalWrite(encoderPinB, HIGH); // use internal pull-ups
- attachInterrupt(1, doEncoderA, CHANGE); // encoder pin on interrupt 0 (pin 2)
- attachInterrupt(0, doEncoderB, CHANGE); // encoder pin on interrupt 1 (pin 3)
- Serial.begin (115200);
- //FASTLED
- FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- currentBlending = BLEND;
- Serial.begin(115200);
- }
- //DEFINE NUMBER OF EFFECTS/////////////////////////////////
- #define NUM_MODES 13 //Change this to max number of effects
- //MAIN LOOP////////////////////////////////////////////////
- void loop() {
- //ENCODER MANAGEMENT///////////////////////////////////////
- // Gyro: do this part before you do the switch cases
- // set the upper and lower limits for counting
- if (encoderPos > NUM_MODES) // this limits the encoder max value
- encoderPos = NUM_MODES;
- if (encoderPos < 0) // this limits the encoder max value
- encoderPos = 0;
- ledMode = encoderPos;
- bool trigger = 0;
- // Gyro: you might have overlooked that trigger is an important part in the game
- if (ledMode != lastCount) trigger = 1; // if it's changed, trigger the different events
- // Gyro: when the dial has been turned = has now a different number, make the trigger active
- Serial.println(encoderPos);
- switch (ledMode) {
- case 0: if (trigger) { BRIGHTNESS=255; Rainbow(); } break; //Rainbow Colors
- // Gyro:
- // if (trigger) is the same as if (trigger == 1)
- // in other words: change to another scene when the dial has been turned.
- // the curly brackets mean something in an if statement !
- // only in the case there is only one line to execute then you do not need the curly brackets.
- // http://www.arduino.cc/en/pmwiki.php?n=Reference/If
- case 1: if (trigger) { BRIGHTNESS=255; RainbowStripe(); } break; //Rainbow Stripe
- case 2: if (trigger) { BRIGHTNESS=255; PartyColors(); } break; //Party Colors
- case 3: if (trigger) { BRIGHTNESS=255; HeatColors(); } break; //Heat Colors
- case 4: if (trigger) { BRIGHTNESS=255; Ocean(); } break; //Ocean Colors
- case 5: if (trigger) { BRIGHTNESS=255; Forest(); } break; //Forrest Colors
- case 6: if (trigger) { BRIGHTNESS=255; Flashlight(); } break; //Solid White
- case 7: if (trigger) { BRIGHTNESS=255; WhiteBlink(); } break; //Blinking White
- case 8: if (trigger) { BRIGHTNESS=255; Pink(); } break; //Solid Pink
- case 9: if (trigger) { BRIGHTNESS=255; Caution(); } break; //Blink Orange Caution
- case 10: if (trigger) { BRIGHTNESS=255; FIRE(); } break; //Blink Fire Red White
- case 11: if (trigger) { BRIGHTNESS=255; PYRO(); } break; //Blink Pyro Red Orange
- case 12: if (trigger) { BRIGHTNESS=255; LEO_Slow(); } break; //Blink LEO Slow
- }
- /*
- //BUTTON MANAGEMENT////////////////////////////////////////
- byte currKeyState = digitalRead(BUTTON_PIN);
- if ((prevKeyState == LOW) && (currKeyState == HIGH)) {
- keyRelease();
- }
- prevKeyState = currKeyState;
- */
- // delay(2000); // slow down the output
- }
- //LIGHT PATTERNS///////////////////////////////////////////
- //RAINBOW COLORS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void Rainbow() {
- FastLED.setBrightness( BRIGHTNESS );
- currentPalette = RainbowColors_p;
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1;
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(SPEEDO);
- }
- //RAINBOW STRIPE~~-~~~~-~~~~-~~~~-~~~~-~~~~-~~~~-~~~~-~~~~~
- void RainbowStripe() {
- FastLED.setBrightness( BRIGHTNESS );
- currentPalette = RainbowStripeColors_p;
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1;
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(SPEEDO);
- }
- //PARTY COLORS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void PartyColors() {
- FastLED.setBrightness( BRIGHTNESS );
- currentPalette = PartyColors_p;
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1;
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(SPEEDO);
- }
- //HEAT COLORS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void HeatColors() {
- FastLED.setBrightness( BRIGHTNESS );
- currentPalette = HeatColors_p;
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1;
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(SPEEDO);
- }
- //OCEAN COLORS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void Ocean() {
- FastLED.setBrightness( BRIGHTNESS );
- currentPalette = OceanColors_p;
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1;
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(SPEEDO);
- }
- //CLOUD COLORS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void Cloud() {
- FastLED.setBrightness( BRIGHTNESS );
- currentPalette = CloudColors_p;
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1;
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(SPEEDO);
- }
- //FORREST COLORS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void Forest() {
- FastLED.setBrightness( BRIGHTNESS );
- currentPalette = ForestColors_p;
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1;
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(SPEEDO);
- }
- //LAVA COLORS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void Lava() {
- FastLED.setBrightness( BRIGHTNESS );
- currentPalette = LavaColors_p;
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1;
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(SPEEDO);
- }
- //FILL COLORS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void FillLEDsFromPaletteColors( uint8_t colorIndex) {
- for( int i = 0; i < NUM_LEDS; i++) {
- leds[i] = ColorFromPalette( currentPalette, colorIndex, BRIGHTNESS, currentBlending);
- colorIndex += STEPS;
- }
- }
- //SOLID WHITE----------------------------------------------
- void Flashlight() {
- fill_solid(leds, NUM_LEDS, CRGB::White);
- FastLED.show();
- }
- //SOLID PINK-----------------------------------------------
- void Pink() {
- fill_solid(leds, NUM_LEDS, CRGB::HotPink);
- FastLED.show();
- }
- //SOLID RED------------------------------------------------
- void Redlight() {
- fill_solid(leds, NUM_LEDS, CRGB::Red);
- FastLED.show();
- }
- //BLINK ORANGE SLOW-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- void Caution() {
- fill_solid(leds, NUM_LEDS, CRGB::Orange);
- FastLED.show();
- delay(1000);
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- FastLED.show();
- delay(1000);
- }
- //BLINK WHITE-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- void WhiteBlink() {
- fill_solid(leds, NUM_LEDS, CRGB::White);
- FastLED.show();
- delay(250);
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- FastLED.show();
- delay(250);
- }
- //FIRE BLINK RED WHITE-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
- void FIRE() {
- fill_solid(leds, NUM_LEDS, CRGB::Red);
- FastLED.show();
- delay(250);
- fill_solid(leds, NUM_LEDS, CRGB::White);
- FastLED.show();
- delay(250);
- }
- //PYRO BLINK RED ORANGE-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- void PYRO() {
- fill_solid(leds, NUM_LEDS, CRGB::Red);
- FastLED.show();
- delay(100);
- fill_solid(leds, NUM_LEDS, CRGB::Orange);
- FastLED.show();
- delay(100);
- }
- //LEO BLINK RED BLUE SLOW-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- void LEO_Slow() {
- fill_solid(leds, NUM_LEDS, CRGB::Red);
- FastLED.show();
- delay(250);
- fill_solid(leds, NUM_LEDS, CRGB::Blue);
- FastLED.show();
- delay(250);
- }
- //LEO BLINK RED BLUE FAST-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- void LEO_Fast() {
- fill_solid(leds, NUM_LEDS, CRGB::Red);
- FastLED.show();
- delay(100);
- fill_solid(leds, NUM_LEDS, CRGB::Blue);
- FastLED.show();
- delay(100);
- }
- /*
- //BUTTON CONTROL///////////////////////////////////////////
- //-called when button is pressed
- void shortKeyPress() {
- Serial.println("short");
- ledMode++;
- if (ledMode > NUM_MODES){
- ledMode=0; }
- }
- // called when key goes from pressed to not pressed
- void keyRelease() {
- Serial.println("key release");
- shortKeyPress();
- }
- */
- //ENCODER CONTROL//////////////////////////////////////////
- void doEncoderA(){ // Encoder A
- if (digitalRead(encoderPinA) == HIGH) { // look for a low-to-high on channel A
- if (digitalRead(encoderPinB) == LOW) { // check channel B to see which way encoder is turning
- encoderPos = encoderPos + 1; } // CW
- else {
- encoderPos = encoderPos - 1; } // CCW
- }
- else { // must be a high-to-low edge on channel A
- if (digitalRead(encoderPinB) == HIGH) { // check channel B to see which way encoder is turning
- encoderPos = encoderPos + 1; } // CW
- else {
- encoderPos = encoderPos - 1; } // CCW
- }
- }
- void doEncoderB(){ // Encoder B
- if (digitalRead(encoderPinB) == HIGH) { // look for a low-to-high on channel B
- if (digitalRead(encoderPinA) == HIGH) { // check channel A to see which way encoder is turning
- encoderPos = encoderPos + 1; } // CW
- else {
- encoderPos = encoderPos - 1; } // CCW
- }
- else { // Look for a high-to-low on channel B
- if (digitalRead(encoderPinA) == LOW) { // check channel B to see which way encoder is turning
- encoderPos = encoderPos + 1; } // CW
- else {
- encoderPos = encoderPos - 1; } // CCW
- }
- }
- //END//////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement