Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++* MIKES DRIP ANIMATION SKETCH 1.4 BETA - 12/22/15 ( File: MIKES_DRIP_ANIMATION_v1_4_beta )*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++* BUTTON DEMO* This Sketch includes the functioning button mode control demo** press K4 and HOLD for 1.2 sec, and it will toggle between DISPLAY and SETTINGS mode. Press and HOLD again to switch back.* In settings mode, K4 works like the other buttons and switches color through red/green/blue for demo.* Pressing K4 will switch color too, BUT with an added feature of switching the color BACK to the one it was BEFORE pressing K4* This way, when K4 is used to switch settings modes, it returns to the same settings mode coming from DISPLAY mode.** RANDOM COLOR FUNCTION** Random colors are added to the "dripColorArray[]" below. Follow instructions as per commas. It won't compile if wrong* A "randomColor_ON" switch turns random ON/OFF (true or false switches ON/OFF)*/// TODO -------- check max power still regulated after brightness changed by button#include "FastLED.h"//#include <avr/pgmspace.h>#define NUM_LEDS 82 // Mike = 82 LEDS (test settings 144)#define tube_A_DATA_PIN 6 // Mike = PIN 6 ( 5 )#define tube_A_CLOCK_PIN 7 // Mike = PIN 7 ( 6 )#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) // array size = array sise by size of elementint ledStartPoint = (NUM_LEDS - 1); // Beginning LED in animation. Since reversed, last LED in array. [NUM_LEDS starts at 1, Array at 0 (-1)]CRGB dripColor = CRGB::Grey; // variable for color of drip DO NOT CHANGE HERE, change defaultDripColor below/*+++++++++++++++++++ ADJUSTMENTS - TWEAK FOR MAXIMUM AWESOMENESS ++++++++++++++++++++++++++++++++++++++++++++++++++* There is interaction between ledBrightness, fadeAmount, and drip(Min/Max)Length* fadeAmount can kill random drip length since fade to black sets end of tail / beginning of space* * Fade trail lengthens with brightness. Setting fadeAmount or dripMinimum too low = tail never goes full off/black (maybe desired)* fadeAmount = 0; solid color throughout drip, no tail, but random drip length works** When tweaking dripSpacings / dripLengths/ dripSpeedSlowing set ledBrightness = 5 and dripColor = CRGB::Red so its easier on the eyes* Then set ledBrightness and dripColor for final display to tweak ledBrightness, fadeAmount, and drip(Min/Max)Length*/// =================== ADJUSTMENT SETTINGS BELOW ===================================================================================================uint8_t ledBrightness = 20; // BRIGHTNESS OF LEDS from 1-255 (usually 5 - 50) too low may flicker, too bright hurts eyes & draws excess currentuint8_t dripSpeedSlowing = 6; // HIGHER NUMBER = SLOWER FALLING DRIPS [actually delay in milliseconds between pixels] (default 5) [Mike = 10]uint8_t faucetDripSpeed = 10; // SPEED OF DRIP WHILE ORIGINATING FROM TOP OF TUBE (FAUCET). 0 = OFF, HIGHER NUMBER = SLOWERuint8_t fadeAmount = 9; // DRIP FADE (TAIL) [0 = NO FADE, RANDOM DRIP LENGTH] HIGHER NUMBER (~20)= SHORTER TAIL. AFFECTED BY BRIGHTNESSuint8_t dripMinimumLength = 30; // MINIMUM LENGTH OF DRIP IN PIXELS (test 50) [Mike = 28]uint8_t dripMaximumLength = 50; // MAXIMUM LENGTH OF DRIP IN PIXELS (test 75) [Mike = 43]uint8_t spaceMinimumLength = 40; // MINIMUM LENGTH OF SPACE IN PIXELS (test 75) [Mike = 43]uint8_t spaceMaximumLength = 90; // MAXIMUM LENGTH OF SPACE IN PIXELS (test 150) [Mike = 86]bool randomColor_ON = false; // true = ON, false = OFF (lower case, no caps)CRGB defaultDripColor = CRGB::Grey; // COLOR OF DRIP this is the color if randomColor = offCRGB g = CRGB::Grey; // Here are some colors for the drips.CRGB a = CRGB::Aqua; // How to use it...CRGB b = CRGB::LightBlue; // Notice the dripColorArray a few lines below. Just add the code from the color list to the left.CRGB m = CRGB::Magenta; // For instance, Grey has the code "g". Just add g, (don't forget comma), and it's one of the random colorsCRGB c = CRGB::Cyan; // The more colors, the less chances for that color to come up. To increase odds, just add the colorCRGB r = CRGB::Red; // more than the others like: {g, g, g, a, b} favors greyCRGB w = CRGB::White; // 140+ colors to pick from - https://github.com/FastLED/FastLED/wiki/Pixel-reference (scroll down long page)CRGB dripColorArray[] = { g, a, r, w, m, c};// NO COMMA AFTER LAST COLOR. COMMAS BETWEEN COLORS, SPACEES OPTIONAL FOR READABILITY//==================== END OF ADJUSTMENTS DO NOT CHANGE VARIABLES BELOW =============================================================================uint8_t numberOfDripColors = ARRAY_SIZE(dripColorArray);CRGB tube_A_leds[NUM_LEDS];// ================================================================= BUTTON INITIALIZATIONS ===========================================================#define DEBOUNCE 10 // how many ms to debounce, 5+ ms is usually plenty#define NUMBUTTONS sizeof(buttons) // determine how big the array up above is, by checking the sizeuint8_t buttons[] = {2, 3, 4, 5}; // Nano button pin numbersuint8_t number_of_modes = 3; // Number of modes to cycle through. Starts at 0.uint8_t selectSetting = 0; // number of current settinguint8_t settingStore = 0; // save current setting to return to same setting after mode switch changes ituint8_t pressed[NUMBUTTONS], justpressed[NUMBUTTONS];uint8_t justreleased[NUMBUTTONS], current_keystate[NUMBUTTONS]; // track if a button is just pressed, just released, or 'currently pressed'uint8_t previous_keystate[NUMBUTTONS];bool Show_Display = true; // Toggles between Display and Settings Modebool K4_pressed = false; // Flag for K4 pressedunsigned long K4_holdTimer = 0; // K4 timer for "Button Long Hold"long debounceTimeCounter = 0;long testTimeCounter = 0;// ====================================================================================================================================================void setup() { set_max_power_in_volts_and_milliamps(5, 2000); // MAXIMUM POWER DRAW = 5V 2A APPROX. FastLED.setBrightness(ledBrightness); FastLED.addLeds<APA102, tube_A_DATA_PIN, tube_A_CLOCK_PIN, BGR>(tube_A_leds, NUM_LEDS); // ============================================================= BUTTON SETUP ======================================================================= Serial.begin(115200); // pinMode(13, OUTPUT); // digitalWrite(13, LOW); // Serial.print("Button checker with "); // Serial.print(NUMBUTTONS, DEC); // Serial.println(" buttons"); uint8_t b; for (b = 0; b < NUMBUTTONS; b++) { // Make input & enable pull-up resistors on switch pins pinMode(buttons[b], INPUT); digitalWrite(buttons[b], HIGH); }}// =====================================================================================================================================================void loop() { buttonScan(); if (Show_Display == true) { displayMode(); } if (Show_Display == false) { settingsMode(); }}// =========================================================== SETTINGS MODE =========================================================================void settingsMode() { switch (selectSetting) // Button K4 is the mode button that loops from mode 0 to the number of modes and back to 0 { case 0: // Mode 0 runs the FastLED display patterns //Serial.println("selectSetting 0"); fillAll(CRGB::Green); // displayMode() loops through all the FastLED display animations digitalWrite(13, LOW); break; case 1: // All other modes stop the FastLED display, and performs control functions //Serial.println("selectSetting 1"); // such as adjusting brightness, speed,etc. fillAll(CRGB::Blue); digitalWrite(13, HIGH); break; case 2: // To add another control function, increase the "number_of_modes =" //Serial.println("selectSetting 2"); // located in the BUTTON INITIALIZATIONS section, and add a case _: fillAll(CRGB::Red); break; // To add another control function, increase the "number_of_modes =" // located in the BUTTON INITIALIZATIONS section, and add a case _: //.................................................++++++++++++++++ ADD MORE SETTINGS HERE ++++++++++++++++++++++++++++++++++++++++++++++++++++++ }}//}// =========================================================== DISPLAY MODE =========================================================================void displayMode() { // ==== ALL THE FastLED PATTERN FUNCTIONS START HERE ==== delay(dripSpeedSlowing); // ***COMMENT THIS LINE OUT ("//") FOR MAX DRIP SPEED*** Kills delay alltogether update_tube_A(); // insert one pixel at a time at end of drip or space in tube A array shift_tube_A(); // shift entire array one pixel for next update_tube pixel insertion FastLED.show();}
Advertisement
Add Comment
Please, Sign In to add comment