Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************************************
- * Oil Rigs Prototype
- * By LucasM
- * 10/20/14
- * V1.1
- * TEST BRANCH - Dual Animation Test
- *
- * Runs Two Animations on different Pins, using 2 Arrays
- * Includes AnimateMarquee, AnimateLine, ClearPixelsInstant, ClearPixelRange
- *
- ******************************************************************************************/
- //Add these libraries
- #include <FastLED.h> //Library for RGB LED Control
- #include <DmxSimple.h> //Library for DMX Control
- #include <Metro.h> //Easy Timer Library
- //Define Constants
- //Define Pins
- #define BUTTON1 2
- #define BUTTON2 3
- #define BUTTON3 5
- //Data Pinsa
- #define PIXEL_PIN1 12
- #define PIXEL_PIN2 11
- #define DMX_PIN 4 //Data Pin for DMX Output, must be 4 on LM's Breakout Board
- //Create other Constants
- //Pixel Counts for Each Array
- const int ARRAY1_SIZE = 300;
- const int ARRAY2_SIZE = 64;
- //Time Out Values for Pixel Animations
- const int CYCLETIMEOUT1 = 255;
- const int CYCLETIMEOUT2 = 400;
- const int CYCLETIMEOUT3 = 500;
- //DMX Channels
- const int DMXZONE1 = 1;
- const int DMXZONE2 = 2;
- const int DMXZONE3 = 3;
- //Values for Various Brightness levels, used in DMX and Pixel operations
- const int HOMEBRIGHT = 100;
- const int FLUXBRIGHT = 150;
- const int MAXBRIGHT = 255;
- //Pixel Ranges for Various Areas
- const int BEG1 = 0;
- const int END1 = 300;
- const int BEG2 = 0;
- const int END2 = 64;
- const int BEG3 = 0;
- const int END3 = 0;
- const int BEG4 = 0;
- const int END4 = 0;
- //Define Color Variables for Animations
- //Hue Rainbow:
- //(0-Red)(32-Orange)(64-Yellow)(96-Green)(128-Aqua)(160-Blue)(192-Purple)(224-Pink)
- //Saturation 0 = White, 255 = Full Color
- const byte HUE1 = 0;
- const byte SAT1 = 255;
- const byte HUE2 = 96;
- const byte SAT2 = 255;
- const byte HUE3 = 160;
- const byte SAT3 = 255;
- const byte HUE4 = 160;
- const byte SAT4 = 0;
- //Create Pixel Array
- CRGB leds1[ARRAY1_SIZE];//Create array for RGB LED Control
- CRGB leds2[ARRAY1_SIZE];//Create array for RGB LED Control
- //Create Pixel Stepper Clocks (In Milliseconds)
- Metro PixelClock_Anim = Metro(50);
- Metro PixelClock_Fade = Metro(10);
- //Define Variables
- int ACycles1 = 0;
- int ACycles2 = 0;
- int ACycles3 = 0;
- int ACycles4 = 0;
- //Setup Starting Values for Variables used to keep track of where the animation is through each loop
- int Tracker1 = BEG1;
- int Tracker2 = BEG2;
- int Tracker3 = BEG3;
- int Tracker4 = BEG4;
- //Brightness Values are used for DMX Controlled lights, AND for functions which dim/brighten slowly
- byte Brightness1 = 0;
- byte Brightness2 = 0;
- byte Brightness3 = 0;
- byte Brightness4 = 0;
- boolean RunPixelA = false; //Used for the Metronome timing Pixel Animation Steps
- boolean RunPixelF = false; //Used for the Metronome timing Pixel Fade Steps
- //Booleans for Animation Run States
- boolean Animation1 = false;
- boolean Animation2 = false;
- boolean Animation3 = false;
- boolean Animation4 = false;
- /*****************************************************************************************
- * SETUP
- *****************************************************************************************/
- void setup() {
- //Setup Pins
- pinMode(BUTTON1, INPUT_PULLUP);
- pinMode(BUTTON2, INPUT_PULLUP);
- pinMode(BUTTON3, INPUT_PULLUP);
- pinMode(PIXEL_PIN1, OUTPUT);
- pinMode(PIXEL_PIN2, OUTPUT);
- pinMode(DMX_PIN, OUTPUT);
- //Other Actions
- FastLED.addLeds<NEOPIXEL, PIXEL_PIN1>(leds1, ARRAY1_SIZE);
- FastLED.addLeds<NEOPIXEL, PIXEL_PIN2>(leds2, ARRAY2_SIZE);
- DmxSimple.usePin(DMX_PIN);
- DmxSimple.maxChannel(512);
- //Start with A Clean Slate
- memset(leds1,0,sizeof(leds1));
- memset(leds2,0,sizeof(leds2));
- FastLED.show();
- delay(1000);
- }
- /*****************************************************************************************
- * LOOP
- *****************************************************************************************/
- void loop() {
- //Check to see if enough time has elapsed to draw the next step for each type of Pixel Animation
- if(PixelClock_Anim.check() == 1){
- RunPixelA = true;
- }
- else {
- RunPixelA = false;
- }
- if(PixelClock_Fade.check() == 1){
- RunPixelF = true;
- }
- else {
- RunPixelF = false;
- }
- //Button 1 - Red Marquee, Pixel Array on First Array
- if(digitalRead(BUTTON1) == LOW){
- Animation1 = true;
- ACycles1 = 0;
- }
- if(ACycles1 == CYCLETIMEOUT1){
- Animation1 = false;
- }
- if(Animation1 == true){//if the button is down
- if(RunPixelA == true){//and it is time to step
- Tracker1 = AnimateMarquee(END1, Tracker1, HUE1, SAT1);
- ACycles1++;
- }
- }
- if(Animation1 == false){
- Tracker1 = ClearPixelsInstant(BEG1, END1, Tracker1);
- }
- //Button 2 - Draw A Green Line On Second Array
- if(digitalRead(BUTTON2) == LOW){
- Animation2 = true;
- ACycles2 = 0;
- }
- if(ACycles2 == CYCLETIMEOUT2){
- Animation2 = false;
- }
- if(Animation2 == true){//if the button is down
- if(RunPixelF == true){//and it is time to step
- //Tracker2 = AnimateLine(BEG2, END2, Tracker2, HUE2, SAT2, MAXBRIGHT);
- ACycles2++;
- }
- }
- if(Animation2 == false){
- //Tracker2 = ClearPixelsInstant2(BEG2, END2, Tracker2);
- }
- }
- /*****************************************************************************************
- * FUNCTIONS
- *****************************************************************************************/
- //#AnimateMarquee
- //Causes a contiuous trail of 5 pixels, spaced by 3 apart, to animate
- //Assumes Start at 0
- //There is probably a more elegant way to code this
- //This is easy to read
- int AnimateMarquee(int EndPixel, int CurrentPixel, int Hue, int Sat){
- //Depending on CurrentPixel Value, Pick the animation case
- const int FLUXBRIGHT = 150;
- const int MAXBRIGHT = 255;
- switch (CurrentPixel){
- case 0:
- leds1[0] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[1] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[2] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[3] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[4] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[5] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[6] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[7] = CHSV(Hue, Sat, MAXBRIGHT);
- break;
- case 1:
- leds1[0] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[1] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[2] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[3] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[4] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[5] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[6] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[7] = CHSV(Hue, Sat, MAXBRIGHT);
- break;
- case 2:
- leds1[0] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[1] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[2] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[3] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[4] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[5] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[6] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[7] = CHSV(Hue, Sat, MAXBRIGHT);
- break;
- case 3:
- leds1[0] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[1] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[2] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[3] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[4] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[5] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[6] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[7] = CHSV(Hue, Sat, FLUXBRIGHT);
- break;
- case 4:
- leds1[0] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[1] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[2] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[3] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[4] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[5] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[6] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[7] = CHSV(Hue, Sat, FLUXBRIGHT);
- break;
- case 5:
- leds1[0] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[1] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[2] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[3] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[4] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[5] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[6] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[7] = CHSV(Hue, Sat, FLUXBRIGHT);
- break;
- case 6:
- leds1[0] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[1] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[2] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[3] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[4] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[5] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[6] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[7] = CHSV(Hue, Sat, FLUXBRIGHT);
- break;
- case 7:
- leds1[0] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[1] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[2] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[3] = CHSV(Hue, Sat, FLUXBRIGHT);
- leds1[4] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[5] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[6] = CHSV(Hue, Sat, MAXBRIGHT);
- leds1[7] = CHSV(Hue, Sat, FLUXBRIGHT);
- break;
- }
- //after picking case, apply to the rest of the range
- for(int i = 7; i < EndPixel; i = i + 8){
- memmove8( &leds1[i], &leds1[0], 8 * sizeof( CRGB ) );
- }
- FastLED.show();
- //Reset at 8, since the function will draw all of the rest for you
- if(CurrentPixel <= 7){
- ++CurrentPixel;
- }
- if(CurrentPixel >= 8){
- CurrentPixel = 0;
- }
- return CurrentPixel;
- }
- //#AnimateLine
- //Starting at one end, a solid line grows to the end
- //Call without Checking the timer to make it appear like they all turn on instantly
- //Adjust Brightness on the fly to make it appear to Glow or Fade
- int AnimateLine(int StartPixel, int EndPixel, int CurrentPixel, byte Hue, byte Saturation, byte Brightness){
- leds2[CurrentPixel] = CHSV(Hue, Saturation, Brightness);
- FastLED.show();
- if(CurrentPixel < EndPixel){
- CurrentPixel++;
- }
- if(CurrentPixel == EndPixel){
- CurrentPixel = StartPixel;
- }
- return CurrentPixel;
- }
- //#ClearPixelsInstant
- //Clear All Pixels Everywhere in the Array
- int ClearPixelsInstant(int StartPixel, int EndPixel, int CurrentPixel){
- memset(leds1,0,sizeof(leds1));
- FastLED.show();
- CurrentPixel = StartPixel;
- return CurrentPixel;
- }
- //#ClearPixelsInstant2
- //Clear All Pixels Everywhere in the Array
- int ClearPixelsInstant2(int StartPixel, int EndPixel, int CurrentPixel){
- memset(leds2,0,sizeof(leds2));
- FastLED.show();
- CurrentPixel = StartPixel;
- return CurrentPixel;
- }
Advertisement
Add Comment
Please, Sign In to add comment