Basic Code Deconstructed — .txt file
/* Using the HEF4794B LED Driver from Philips
* Spec sheet at:
* http://webzone.k3.mah.se/projects/arduino-workshop/
upload/download.asp?file=51110204007987&enc=False&lang=english
* Modified from script at http://arduino.cc/en/Tutorial/LEDDriver
* by David Cuartielles, Marcus Hannerstig
*
* First, some caveats. The board pictured on the site doesn't make clear
* that the wiring of the LEDs is from chip to resistor to LED to +V.
* To me, it looks like it's the other way around, but it's not.
*
* Multi 4794s Version 1: Using an Array to set a series of 16 on and off LEDs
*/
// Setup variables
// Pin variables // Description of what pin is connected and what it does:
int data = 9; // - Data output, connected to pin 2 on the first 4794.
// The Arduino will send a series of HIGH and LOW outputs
// to the 4794, which are stored in the 4794's
// 8 Stage Shift Register each time the clock is pulsed.
// When the Shift Register is full, it passes the bit
// in its last postion out the Serial Output (pin 9 or 10).
// This allows data to be passed from one 4794 to the next.
int strobe = 8; // - Strobe output, connected to pin 1 on each 4794
// The Arduino will send a pulse to the Strobe Input on the
// 4794 each time all the on's and off's are considered
// completed (from coming down the data line). This tells
// the 4794 to take the 8 bits stored in its Shift Register
// and move them to its Storage Register.
// If the Output Enabled pin is set to HIGH, the outputs
// (pins 4-7 and 11-14) will reflect the on or off state
// that's held in the Storage Register.
int clock = 10; // - Clock output, connected to pin 3 on each 4794.
// The 4794 uses HIGH and LOW pulses from the Arduino
// as a Clock.
int eo = 11; // - Output Enable output, referred to as "EO" in the
// 4794 docs. Connected to pin 15 on each 4794
// The OE must be HIGH for the LEDs to be on.
// LED positions
// Second Set First Set
// 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
int myArray[] = {0,1,0,1,0,1,0,1, 0,0,0,1,1,0,0,0};
// - myArray is a variable for an array which will
// correspond to the ons and offs of the LEDs.
// The first half of the array will go to the second set
// of 8 led's, and the order will go from right to left.
// Standard initializing of pins
void setup() {
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(strobe, OUTPUT);
pinMode(eo, OUTPUT);
}
// Function to pulse the clock
void PulseClock(void) { // This function sends a LOW/HIGH/LOW pulse to the 4794
digitalWrite(clock, LOW); // to tell it to take a single bit (a 1 or 0) of info you've
delayMicroseconds(40); // set up in the loop. Its sends a pulse something like this:
digitalWrite(clock, HIGH); // ..°°°°°.
delayMicroseconds(40); // The 4794 looks for the front of the pulse, when it goes from
digitalWrite(clock, LOW); // LOW to HIGH, and then accepts the HIGH or LOW input from the
} // data pin into its Shift Register.
// The Main Loop
void loop() {
for (int count = 0; count < 16; count++) {
// Step thru the values in myArray with count.
digitalWrite(data,myArray[count]); // Set the data output pin on the Arduino to 1 or 0,
// which is equivalent to HIGH or LOW.
// This test is true when we've gone thru all the values in the array.
if (count == 15){
digitalWrite(eo, LOW); // Turn off the outputs on the 4794 for a moment.
digitalWrite(strobe, HIGH); // Send a HIGH pulse to the Strobe input, which will cause the 4794s
// to move the 1's and 0's from the Shift Register to the
// Storage Register.
PulseClock(); // Tick the clock.
digitalWrite(eo, HIGH); // Turn the outputs back on.
digitalWrite(strobe, LOW); // Every
} else {
PulseClock(); // Tick the clock, which tells the 4794 to take in the 1 or 0
// into its Shift Register and be ready for the next one.
}
}
}
Animated Version — .txt file
/* 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
}