/* ____ __ __ ____ ____ _____ ____ __ __ ____ ____ ____ /\ _`\ /\ \/\ \ /\ _`\ /\ _`\ /\ __`\/\ _`\ /\ \/\ \/\ _`\ /\ _`\ /\ _`\ \ \ \/\_\\ \ \ \ \ \ \,\L\_\ \ \L\_\ \ \/\ \ \ \L\_\ \ `\\ \ \ \/\_\\ \ \L\_\ \ \L\ \ \ \ \/_/_\ \ \ \ \ \/_\__ \\ \ _\L\ \ \ \ \ \ _\L\ \ , ` \ \ \/_/_\ \ _\L\ \ , / \ \ \L\ \\ \ \_/ \ /\ \L\ \ \ \L\ \ \ \\'\\ \ \L\ \ \ \`\ \ \ \L\ \\ \ \L\ \ \ \\ \ \ \____/ \ `\___/ \ `\____\ \____/\ \___\_\ \____/\ \_\ \_\ \____/ \ \____/\ \_\ \_\ \/___/ `\/__/ \/_____/\/___/ \/__//_/\/___/ \/_/\/_/\/___/ \/___/ \/_/\/ / ____ _____ ____ ______ __ __ ____ /\ _`\ /\ __`\/\ _`\ /\__ _\/\ \/\ \/\ _`\ \ \ \L\_\ \ \/\ \ \ \L\ \ \/_/\ \/\ \ \_\ \ \ \L\_\ \ \ _\/\ \ \ \ \ \ , / \ \ \ \ \ _ \ \ _\L \ \ \/ \ \ \_\ \ \ \\ \ \ \ \ \ \ \ \ \ \ \L\ \ \ \_\ \ \_____\ \_\ \_\ \ \_\ \ \_\ \_\ \____/ \/_/ \/_____/\/_/\/ / \/_/ \/_/\/_/\/___/ ____ __ __ __ ____ ____ _____ __ __ ____ ____ ____ /\ _`\ /\ \/\ \/\ \ /\ _`\ /\ _`\ /'\_/`\/\ __`\/\ \/\ \/\ _`\ /\ _`\ /\ _`\ \ \ \L\ \ \ \ \ \ \ \ \ \,\L\_\ \ \L\_\/\ \ \ \/\ \ \ `\\ \ \ \L\_\ \ \L\_\ \ \L\ \ \ \ ,__/\ \ \ \ \ \ \ __\/_\__ \\ \ _\L\ \ \__\ \ \ \ \ \ \ , ` \ \ \L_L\ \ _\L\ \ , / \ \ \/ \ \ \_\ \ \ \L\ \ /\ \L\ \ \ \L\ \ \ \_/\ \ \ \_\ \ \ \`\ \ \ \/, \ \ \L\ \ \ \\ \ \ \_\ \ \_____\ \____/ \ `\____\ \____/\ \_\\ \_\ \_____\ \_\ \_\ \____/\ \____/\ \_\ \_\ \/_/ \/_____/\/___/ \/_____/\/___/ \/_/ \/_/\/_____/\/_/\/_/\/___/ \/___/ \/_/\/ / FEATURES: 3 MODES: NORMAL, KNIGHT RIDER, AND RANDOM LENGTH BUTTON SETS THE MAXIMUM NUMBER OF PINS (ie. values 2 through 8) CODE AND SCHEMATIC BY JOEY MARIANO ANIMAL-STYLE.COM BIG THANKS TO VBLANK (WIL LINDSAY) FOR THE PROGRAMMING LESSONS AND TO BATSLY ADAMS (ANDREW REITANO) FOR SCHEMATIC ADVICE THIS IS VERSION 1.0 PLANS FOR THE FUTURE: - TAP TEMPO - GAMEBOY LINKER CABLE INTERFACE (PULSE SEQUENCING COULD HAPPEN IN RELATION TO LSDJ'S CLOCK PULSE) */ int ledCnt = 8; int ledPins[8] = { 13, 12, 11, 10, 9, 8, 7, 6}; //set he array of pins const int speedPin = 1; const int modeButtonPin = 2; // the pin that the pushmodeButton is attached to const int lengthButtonPin = 4; int led = 1; int lengthButtonState = 0; int lastLengthButtonState = 0; int lengthButtonCounter = 0; int modeButtonCounter = 1; // counter for the number of modeButton presses int modeButtonState = 0; // current state of the modeButton int lastModeButtonState = 0; // previous state of the modeButton int whatPin = 0; int previousWhatPin = 1; // on the random function this will store which pin was triggered last unsigned long previousMillis = 0; // will store last time relay was updated unsigned long interval = 0; // interval at which to blink (controlled by speed pin) unsigned long lengthDebounce = 0; unsigned long modeDebounce = 0; int debounce = 100; int randomRange = 0; void setup() { for(int i=0; i debounce){ lengthDebounce = millis(); if (lengthButtonState != lastLengthButtonState){ if (lengthButtonState == HIGH){ allOff(); lengthButtonCounter++; } } lastLengthButtonState = lengthButtonState; } //Check Mode modeButtonState = digitalRead(modeButtonPin); if(millis() - modeDebounce > debounce){ modeDebounce = millis(); if (modeButtonState != lastModeButtonState) { if (modeButtonState == HIGH) { allOff(); modeButtonCounter++; } } lastModeButtonState = modeButtonState; } switch (modeButtonCounter){ case 1: if((lengthButtonCounter == 0) && (whatPin == 8)){ whatPin = 0; } if((lengthButtonCounter == 1) && (whatPin == 7)){ whatPin = 0; } if((lengthButtonCounter == 2) && (whatPin == 6)){ whatPin = 0; } if((lengthButtonCounter == 3) && (whatPin == 5)){ whatPin = 0; } if((lengthButtonCounter == 4) && (whatPin == 4)){ whatPin = 0; } if((lengthButtonCounter == 5) && (whatPin == 3)){ whatPin = 0; } if((lengthButtonCounter == 6) && (whatPin == 2)){ whatPin = 0; } if(lengthButtonCounter == 7){ lengthButtonCounter = 0; } normal(); break; case 2: if((lengthButtonCounter == 0) && (whatPin == 14)){ whatPin = 0; } if(lengthButtonCounter == 1){ if(whatPin == 7){ whatPin = 9; } if(whatPin == 14){ whatPin = 0; } } if(lengthButtonCounter == 2){ if(whatPin == 6){ whatPin = 10; } if(whatPin == 14){ whatPin = 0; } } if(lengthButtonCounter == 3){ if(whatPin == 5){ whatPin = 11; } if(whatPin == 14){ whatPin = 0; } } if(lengthButtonCounter == 4){ if(whatPin == 4){ whatPin = 12; } if(whatPin == 14){ whatPin = 0; } } if(lengthButtonCounter == 5){ if(whatPin == 3){ whatPin = 13; } if(whatPin == 14){ whatPin = 0; } } if(lengthButtonCounter == 6){ if(whatPin == 2){ whatPin = 14; } if(whatPin == 14){ whatPin = 0; } } if(lengthButtonCounter >=7){ lengthButtonCounter = 0; } knightRider(); break; case 3: if ( lengthButtonCounter == 0){ randomRange = 7; } if ( lengthButtonCounter == 1){ randomRange = 6; } if ( lengthButtonCounter == 2){ randomRange = 5; } if ( lengthButtonCounter == 3){ randomRange = 4; } if ( lengthButtonCounter == 4){ randomRange = 3; } if ( lengthButtonCounter == 5){ randomRange = 2; } if ( lengthButtonCounter == 6){ randomRange = 1; } if ( lengthButtonCounter >= 7){ randomRange = 7; lengthButtonCounter = 0; } whatPin = int(random(0,randomRange)); crazy(); break; case 4: modeButtonCounter = 1; break; } } void normal(){ if (millis() - previousMillis > interval) { previousMillis = millis(); whatPin = whatPin + 1; switch (whatPin){ case 1: led1(); break; case 2: led2(); break; case 3: led3(); break; case 4: led4(); break; case 5: led5(); break; case 6: led6(); break; case 7: led7(); break; case 8: led8(); break; } } } void knightRider(){ if (millis() - previousMillis > interval) { // save the last time you blinked the LED previousMillis = millis(); whatPin = whatPin + 1; switch (whatPin){ case 1: led1(); break; case 2: led2(); break; case 3: led3(); break; case 4: led4(); break; case 5: led5(); break; case 6: led6(); break; case 7: led7(); break; case 8: led8(); break; case 9: led7(); break; case 10: led6(); break; case 11: led5(); break; case 12: led4(); break; case 13: led3(); break; case 14: led2(); break; } } } void crazy(){ if (millis() - previousMillis > interval) { previousMillis = millis(); if(whatPin == previousWhatPin){ whatPin++; if(whatPin >= 8){ whatPin = 1; } } if (whatPin == 0){ led1(); previousWhatPin = whatPin; } if (whatPin == 1){ led2(); previousWhatPin = whatPin; } if (whatPin == 2){ led3(); previousWhatPin = whatPin; } if (whatPin == 3){ led4(); previousWhatPin = whatPin; } if (whatPin == 4){ led5(); previousWhatPin = whatPin; } if (whatPin == 5){ led6(); previousWhatPin = whatPin; } if (whatPin == 6){ led7(); previousWhatPin = whatPin; } if (whatPin == 7){ led8(); previousWhatPin = whatPin; } } } void allOff(){ for(int i=0; i