/* Using the HEF4794B LED Driver from Philips * Modified from script at http://arduino.cc/en/Tutorial/LEDDriver * by David Cuartielles, Marcus Hannerstig * * Multi 4794s Version 2: Using an Array to animate a series of 16 on and off LEDs */ // Setup variables int data = 9; // - Data output, connected to pin 2 on the first 4794 int strobe = 8; // - Strobe output, connected to pin 1 on each 4794 int clock = 10; // - Clock output, connected to pin 3 on each 4794. int eo = 11; // - Output Enable output, connected to pin 15 on each 4794 int potPin = 0; // - Potenitometer Analog input pin on the Arduino, used for variable timing // LED positions // Second Set First Set // 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 int myArray1[] = {0,0,1,0,0,1,0,0, 0,0,1,0,0,1,0,0}; int myArray2[] = {1,0,0,1,0,0,1,0, 0,1,0,0,1,0,0,1}; int myArray3[] = {0,1,0,0,1,0,0,1, 1,0,0,1,0,0,1,0}; // Each array holds a chase lighting animation position, but with the first and second // halves of the array animating in opposite directions. int arrayCount = 1; // A variable to track which array will be used in the Main Loop int myArray[15]; // An empty array with 16 positions to hold the contents of the 3 arrays above // Standard initializing of pins void setup() { pinMode(data, OUTPUT); pinMode(clock, OUTPUT); pinMode(strobe, OUTPUT); pinMode(eo, OUTPUT); Serial.begin(9600); } // Function to pulse the clock void PulseClock(void) { digitalWrite(clock, LOW); delayMicroseconds(40); digitalWrite(clock, HIGH); delayMicroseconds(40); digitalWrite(clock, LOW); } // The Main Loop void loop() { // A cascading set of if then statments to move thru the three different arrays if (arrayCount == 1) { // When arrayCount is 1, step thru myArray and for (int count = 0; count < 16; count++) { // set each of its array positions to the value myArray[count] = myArray1[count]; // in the same position in myArray1 } }else if (arrayCount == 2) { // Likewise for myArray2 for (int count = 0; count < 16; count++) { myArray[count] = myArray2[count]; } }else { // And for myArray3 for (int count = 0; count < 16; count++) { myArray[count] = myArray3[count]; } } // Move thru 1,2 and 3 and back to 1 again each cycle of the Main Loop if (arrayCount < 3) { arrayCount++; }else{ arrayCount = 1; } for (int count = 0; count < 16; count++) { // Step thru the values in myArray with count. digitalWrite(data,myArray[count]); if (count == 15){ digitalWrite(eo, LOW); digitalWrite(strobe, HIGH); PulseClock(); digitalWrite(eo, HIGH); digitalWrite(strobe, LOW); } else { PulseClock(); } } delay(analogRead(potPin)); // Use the value in the analog input from the potentiometer as a timer }