/* Glitch Shoes - putting the patterns into an array Multi-mode moving LED light pattern Author: Jon Jennings http://jonjennings.org/ Date: November 2011 Licence: This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. http://creativecommons.org/licenses/by-sa/3.0/ */ // Define the pins that we're using for our hardware int ledPins[] = { 9, 10, 11, 3 }; int buttonPin = 12; // The current effects mode int mode = 0; // LED patterns // Note that in this version of the code, only pattern1[] is accessed int pattern2[][5] = { { 200, HIGH, LOW, LOW, LOW}, { 200, LOW, HIGH, LOW, LOW}, { 200, LOW, LOW, HIGH, LOW}, { 200, LOW, LOW, LOW, HIGH}}; int pattern3[][5] = { { 100, LOW, LOW, LOW, LOW}, { 200, HIGH, LOW, LOW, LOW}, { 200, HIGH, HIGH, LOW, LOW}, { 200, LOW, HIGH, HIGH, LOW}, { 200, LOW, LOW, HIGH, HIGH}, { 200, LOW, LOW, LOW, HIGH}, { 400, LOW, LOW, LOW, LOW}}; int pattern1[][5] = { { 20, HIGH, HIGH, HIGH, HIGH}, { 140, LOW, LOW, LOW, LOW}, { 40, HIGH, HIGH, HIGH, HIGH}, {1900, LOW, LOW, LOW, LOW}}; void setup() { // Be sure the on-board LED is off pinMode(13, OUTPUT); digitalWrite(13, 0); // Set our LED lines to be outputs for (int pin = 0 ; pin < sizeof(ledPins)/sizeof(ledPins[0]) ; pin++) { pinMode(ledPins[pin], OUTPUT); } // And configure our mode-switching button pinMode(buttonPin, INPUT); digitalWrite(buttonPin, HIGH); // Set the button closing to generate an interrupt call // Note this version of code doesn't actually use the button action for anything attachInterrupt(0, buttonInterrupt, FALLING); // Turn on the serial port for debug text Serial.begin(9600); } // Main program loop void loop() { // Remember which step of the array we're currently on static int currentStep = 0; // Remember the time when we entered this step static unsigned long lastChangeTime = 0; // If it's time to move to the next array step... if (millis() > lastChangeTime + pattern1[currentStep][0]) { currentStep++; Serial.println(currentStep); lastChangeTime = millis(); // Remember the step change time // If our step counter has moved off the end of the pattern array, set it back to the start if (currentStep >= (sizeof(pattern1)/sizeof(pattern1[0]))) currentStep=0; // For each LED, write out the appropriate value from the current pattern row for (int led=0 ; led < sizeof(ledPins)/sizeof(ledPins[0]) ; led++) { digitalWrite(ledPins[led], pattern1[currentStep][led+1]); } } } // end of the loop() // Handle the interrupt from the button being pressed // and use it to change the effects mode // (Note: in this version of the code we don't actually use the mode variable for anything) void buttonInterrupt() { mode += 1; Serial.print("Interrupt: mode is now "); Serial.println(mode); }