-A +A

 

Arduino & 4794 Chip: LED Driver 1

Using an Array to set LEDs

/* 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.
 *
 * Variation 1: Using an Array to set a series of on and off LEDs
 * This version uses a byte in myByte to hold eight 1's and 0's to set the
 * LEDs to on or off. 
 */


int data = 9;            // data output, connected to pin 2 on the 4794
int strobe = 8;          // strobe output, connected to pin 1 on the 4794
int clock = 10;          // clock output, connected to pin 3 on the 4794
int eo = 11;             // Output Enable output, referred to as "EO" in the
                         // 4794 docs. Connected to pin 15 on the 4794       
int myArray[] = {1,0,0,0,0,0,0,1}; // Variable for an array which will correspond to the 
                                     // ons and offs of the LEDs.

void setup()             // Standard initializing of pins
{
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(strobe, OUTPUT);
  pinMode(eo, OUTPUT);
}

void PulseClock(void) {          // This function sends a tick to the clock on the 4794
    digitalWrite(clock, LOW);    // to tell it to take the byte of info you've set up in 
    delayMicroseconds(20);       // the loop. Its sends a pulse something like this:
    digitalWrite(clock, HIGH);   // ..°°°°°.....
    delayMicroseconds(50);       // Documented on page 6 of the HEP4794 manual
    digitalWrite(clock, LOW);    // 
}

void loop() {
  for (int count = 0; count < 8; count++) {
     // Step thru the bits in myByte with count. 
    digitalWrite(data,myArray[count]);
    if (count == 7){                // This test tells us we've built up a whole byte (0-7) in
                                    // the 4794. It should look just like the 1's and 0's in myArray.
    digitalWrite(eo, LOW);          // Send a signal to the Output Enable pin to allow the chip to
                                    // receive data... I think.
    digitalWrite(strobe, HIGH);     // Send a signal to the Strobe pin to, well, I'm not sure why...
    }
    PulseClock();                   // Tick the clock, which tells the 4794 to take in the byte
                                    // and be ready for the next one.
    digitalWrite(eo, HIGH);         // Set the Output Enable pin to not receive data
  }
    delayMicroseconds(20);          // Wait a tiny bit
    digitalWrite(strobe, LOW);      // Not sure why...  
    delay(100);                     // wait a little while. This number can be turned up to animate changes
                                    // in the lighting pattern if you change myByte each time.
}

Arduino & 4794 Chip: LED Driver 2

Using Bitwise Stuff

/* Using the HEF4794B LED Driver from Philips
 * (Also known as a Serial-to-parallel converter)
 * 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.
 *
 * Variation 2: This version uses a byte in myByte to hold eight 1's and 0's to set the
 * LEDs to on or off. It also substitutes using binary numbers and port manipulation to set
 * the state of all digital pins
 */


int data = 9;            // data output, connected to pin 2 on the 4794
int strobe = 8;          // strobe output, connected to pin 1 on the 4794
int clock = 10;          // clock output, connected to pin 3 on the 4794
int eo = 11;             // Output Enable output, referred to as "EO" in the
                         // 4794 docs. Connected to pin 15 on the 4794        
byte myByte = B11101011; // Variable for a byte which will correspond to 
                         // the on/off status of the LEDs

void setup()
{
  //      76543210        // DRDD and DRDB are direct ways to set the INPUT or OUTPUT 
  DDRD = B00000000;       // values of digital pins 0 - 15 on the Arduino. A 1 or a 0
  //      111111          // represents the OUTPUT or INPUT of a specific pin. 
  //      54321098        // DRDD stands for pins 0-7, and DRDB for pins 8-15
  DDRB = B00001111;       // In this example, I'v set pins 8,9,10 and 11 to OUTPUT and
                          // all the others to INPUT. 
                          // SPECIAL NOTE: Don't ever set pin 0 to 1 our you'll destroy the 
                          // ability to program the Arduino!
                          // See: http://arduino.cc/en/Reference/PortManipulation
}

void PulseClock(void) {          // This function sends a tick to the clock on the 4794
    digitalWrite(clock, LOW);    // to tell it to take the byte of info you've set up in 
    delayMicroseconds(20);       // the loop. Its sends a pulse something like this:
    digitalWrite(clock, HIGH);   // ..°°°°°.....
    delayMicroseconds(50);       // Documented on page 6 of the HEP4794 manual
    digitalWrite(clock, LOW);    // 
}

void loop() {
  for (int count = 0; count < 8; count++) {
     // Step thru the bits in myByte with count. 
    if (myByte & (1 << count)) {    // Use the bitwise operator "<<" to shift "1" thru 8 steps 
                                    // like this: 
                                    // 1 << 0 is 00000001
                                    // 1 << 1 is 00000010
                                    // 1 << 2 is 00000100
                                    // 1 <<3 is 00001000  and so on...
                                    // the "&" compares each binary number and returns 1, 
                                    // when there is a 1 in each number, like this:
                                    //          11100111    11100111    11100111    11100111   
                                    //        & 00000001  & 00000010  & 00000100  & 00001000 
                                    //          --------    --------    --------    -------- 
                                    // Result:  00000001    00000010    00000100    00000000
                                    // In the first three tests, there was a match, so they all 
                                    // returned a non-zero number, which is TRUE in boolean logic
      digitalWrite(data, HIGH);     // so we do what's in the first half of this if/else statement                
    } else {                        // In the fourth test above, there was no 1 & 1, so the result
      digitalWrite(data, LOW);      // was false (all 0's) and we do the "else" part of the statement.
                                    // What we're doing is sending a bunch of HIGH's and LOW's out
                                    // of the data pin (pin 9) on the Arduino to the data read pin on the 
                                    // 4794 (pin 2).
    }
    if (count == 7){                // This test tells us we've built up a whole byte (0-7) in
                                    // the 4794. It should look just like the 1's and 0's in myByte.
    digitalWrite(eo, LOW);          // Send a signal to the Output Enable pin to allow the chip to
                                    // receive data... I think.
    digitalWrite(strobe, HIGH);     // Send a signal to the Strobe pin to, well, I'm not sure why...
    }
    PulseClock();                   // Tick the clock, which tells the 4794 to take in the byte
                                    // and be ready for the next one.
    digitalWrite(eo, HIGH);         // Set the Output Enable pin to not receive data
  }
    delayMicroseconds(20);          // Wait a tiny bit
    digitalWrite(strobe, LOW);      // Not sure why...  
    delay(100);                     // wait a little while. This number can be turned up to animate changes
                                    // in the lighting pattern if you change myByte each time.
}

Arduino & 4794 Chip: LED Driver 3

Animating the LEDs

/* Using the HEF4794B LED Driver from Philips
 * (Also known as a Serial-to-parallel converter)
 * 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
 *
 * Variation 3: Animating the LEDs
 */


int data = 9;            // data output, connected to pin 2 on the 4794
int strobe = 8;          // strobe output, connected to pin 1 on the 4794
int clock = 10;          // clock output, connected to pin 3 on the 4794
int eo = 11;             // Output Enable output to pin 15 on the 4794    
int potPin = 0;
byte myByteArray[] = {B00100100, B01001001, B10010010}; // An array of 1's and 0's
                         // which will create classic Vegas-style chase lighting
int countArray = 0;      // A counter to step thru the array in myByteArray

void setup()
{
  Serial.begin(9600);
  //      76543210
  DDRD = B00000000;       
  //      111111          
  //      54321098        
  DDRB = B00001111;   
  //      --543210        // Set the analog port inputs. You can't set 6 and 7, btw.
  DDRC = B00000001;      
}

void PulseClock(void) {          // This function sends a tick to the clock on the 4794
    digitalWrite(clock, LOW);    // to tell it to take the byte of info you've set up in 
    delayMicroseconds(20);       // the loop. Its sends a pulse something like this:
    digitalWrite(clock, HIGH);   // ..°°°°°.....
    delayMicroseconds(50);       // Documented on page 6 of the HEP4794 manual
    digitalWrite(clock, LOW);    // 
}

void loop() {
  if(countArray < 3) {           // If countArray is less than 3, send the byte in the
                                 // array position to the 4794 and increment countArray
    for (int countByte = 0; countByte < 8; countByte++) {
      if (myByteArray[countArray] & (1 << countByte)) {    
        digitalWrite(data, HIGH);                     
      } else {                 
        digitalWrite(data, LOW);     
      }
      if (countByte == 7){   
      digitalWrite(eo, LOW);         
      digitalWrite(strobe, HIGH);    
      }
      PulseClock();                   
      digitalWrite(eo, HIGH);   
    }
    delayMicroseconds(20);          
    digitalWrite(strobe, LOW);
    countArray++;                        // Increment countArray
    int mySpeed = analogRead(potPin)*2;  // Use the potPin to set the speed of the lighting
    delay(mySpeed);                      // Wait a little while. This number can be turned
                                         // up to change animation speed.
  } else {
    countArray = 0;                      // Reset countArray
  }
}

Break

Review of your Sketches for Final Assignment

Let's see'm