Loading...

Learning   Examples | Foundations | Hacking | Links

LED Driver

This example makes use of an LED Driver in order to control an almost endless amount of LEDs with only 4 pins. We use the 4794 from Philips. There is more information about this microchip that you will find in its datasheet.

An LED Driver has a shift register embedded that will take data in serial format and transfer it to parallel. It is possible to daisy chain this chip increasing the total amount of LEDs by 8 each time.

The code example you will see here is taking a value stored in the variable dato and showing it as a decoded binary number. E.g. if dato is 1, only the first LED will light up; if dato is 255 all the LEDs will light up.

Example of connection of a 4794

 
/* Shift Out Data
 * --------------
 * 
 * Shows a byte, stored in "dato" on a set of 8 LEDs
 *
 * (copyleft) 2005 K3, Malmo University
 * @author: David Cuartielles, Marcus Hannerstig
 * @hardware: David Cuartielles, Marcos Yarza
 * @project: made for SMEE - Experiential Vehicles
 */


int data = 9;
int strob = 8;
int clock = 10;
int oe = 11;
int count = 0;
int dato = 0;

void setup()
{
  beginSerial(9600);
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(strob, OUTPUT);
  pinMode(oe, OUTPUT);
}

void PulseClock(void) {
    digitalWrite(clock, LOW);
    delayMicroseconds(20);
    digitalWrite(clock, HIGH);
    delayMicroseconds(50);
    digitalWrite(clock, LOW);
}

void loop()
{
   dato = 5;
   for (count = 0; count < 8; count++) {
    digitalWrite(data, dato & 01);
    //serialWrite((dato & 01) + 48);
    dato>>=1;
    if (count == 7){
    digitalWrite(oe, LOW);
    digitalWrite(strob, HIGH);

    }
    PulseClock();
     digitalWrite(oe, HIGH);
 }

  delayMicroseconds(20);
  digitalWrite(strob, LOW);
  delay(100);


  serialWrite(10);
  serialWrite(13);
 delay(100);                  // waits for a moment
}