Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Looping program for 4794 shiftout controller on: March 03, 2007, 06:18:07 pm
Hey everybody,

I'm trying to sequence my shiftout controller so that each LED will come off sequentially one after another.

I've managed to get the sequence down but so far have been unable to get the program to loop.

I'm thinking i'm using the wrong type of loop (maybe an if clause instead of a for). If anybody could give me some suggestions i'd really appreciate it!

Thanks.
(the code is based on the shiftout program that was in the examples)


int data = 9;
int strob = 8;
int clock = 10;
int oe = 11;
int count = 0;
int dato[8] = {1,2,4,8,16,32,64,128};  // dato is a varible we use to send data to the LEDs


void setup()
{
  //Serial.begin(9600);    // uncomment the serial-related lines to monitor the program's progress
  pinMode(data, OUTPUT);  // declare all the control pins as outputs
  pinMode(clock, OUTPUT);
  pinMode(strob, OUTPUT);
  pinMode(oe, OUTPUT);
}


// sends a pulse to the 4794 indicating that
// it is time to load data
void PulseClock(void) {
  digitalWrite(clock, LOW);
  delayMicroseconds(10);
  digitalWrite(clock, HIGH);
  delayMicroseconds(100);
  digitalWrite(clock, LOW);
}

void loop()
{
  //dato = 64;  // if dato equals 129 the first and last LED will be on
  

  // go through the "dato" variable and send it bit by bit over the data pin
for  (int i = 0; i < 1000; i++)
{
  for (count = 0; count < 8; count++) {
     digitalWrite(data, dato[count] & 01);
    //Serial.print((dato & 01) + 48, BYTE);
    dato[count]>>=1;
    if (count == 7){
      digitalWrite(oe, LOW);
      digitalWrite(strob, HIGH);
    }
      
    PulseClock();
    digitalWrite(oe, HIGH);
  }
  

  
  delayMicroseconds(20);

  digitalWrite(oe, HIGH);
  digitalWrite(strob, LOW);
  
  delay(200);

    
  //Serial.println();
  delay(200);                  // waits for a second
  count = 0;
}

}
Pages: [1]