LED Chaser

I've got a project to do an LED chaser. I've been looking all over google and on here for a couple of days and all I can find is a PIC version of exactly what I want to do.

If someone could help me translate this to arduino code it'll be a lot of help. As for hard ware on my end, I'm going to have 8 LEDs running through a 74hc595 shift register using an arduino uno r3. I can wire it all up, but when it comes to code I'm completely lost.

This might help:

If not, post what code you have and we can look at it.

Here's what I have so far. Although I can't figure out how to do a few light patterns. One being LEDs lighting up at random and the other looking like this..

00000000
10000001
01000010
00100100
00011000
10011001
01011010
00111100
10111101
01111110
11111111

I'd also like to figure out how to make it select at random a pattern to display rather than repeating the same order that they're in, in the script. This is part of a larger project that'll have several of these, but once I can figure out the code for one I can just add on to that.

// Set Pins
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;

// create variables
int ispeed;
int output;
boolean up;

void setup() {
  // initialise pin states
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  // initialise variable states
  up = true;
  output = 1;
  ispeed = 40;

  // scanner style led scrolling
  for (int j = 0; j < 253; j++){
    // count from 0 to 255 and display the number
    // on the LEDs
    // take the latchPin low so
      // the LEDs don't change while you're sending in bits:
      digitalWrite(latchPin, LOW);
      // shift out the bits:
      shiftOut(dataPin, clockPin, MSBFIRST, output);
      //take the latch pin high so the LEDs will light up:
      digitalWrite(latchPin, HIGH);
      // pause before next value:
      if (up){output = output << 1;}
      else {output = output >> 1;}
      if ((output == 0b10000000) || (output == 0b00000001)){up = !up;}
      delay(ispeed);
  }

  // refresh rate example
  for (int j = 0; j < 200; j++){
    // count from 0 to 255 and display the number
    // on the LEDs
    output = 1;
    for (int i = 0; i < 8; i++) {
      // take the latchPin low so
      // the LEDs don't change while you're sending in bits:
      digitalWrite(latchPin, LOW);
      // shift out the bits:
      shiftOut(dataPin, clockPin, MSBFIRST, output);
      //take the latch pin high so the LEDs will light up:
      digitalWrite(latchPin, HIGH);
      // pause before next value:
      output = output << 1;
      delay(ispeed);

    }
    if(ispeed > 1){ispeed = ispeed-1;}
  }

  // binary counter
  ispeed = 50;
  for (output = 0; output < 256; output++){
    // take the latchPin low so
      // the LEDs don't change while you're sending in bits:
      digitalWrite(latchPin, LOW);
      // shift out the bits:
      shiftOut(dataPin, clockPin, MSBFIRST, output);
      //take the latch pin high so the LEDs will light up:
      digitalWrite(latchPin, HIGH);
      // pause before next value:
      delay(ispeed);
  }
}

EDIT

Also I have an issue with one of the patterns I already have. (i'll list the code after) Basically the LEDs blink increasingly faster until it's just "on". Problem is that all of the LEDs stay on for a good second and that kinda kills the flow of the other patterns. Any way I can stop it at a certain feq. or something like that?

  // refresh rate example
  for (int j = 0; j < 200; j++){
    // count from 0 to 255 and display the number
    // on the LEDs
    output = 1;
    for (int i = 0; i < 8; i++) {
      // take the latchPin low so
      // the LEDs don't change while you're sending in bits:
      digitalWrite(latchPin, LOW);
      // shift out the bits:
      shiftOut(dataPin, clockPin, MSBFIRST, output);
      //take the latch pin high so the LEDs will light up:
      digitalWrite(latchPin, HIGH);
      // pause before next value:
      output = output << 1;
      delay(ispeed);

    }
    if(ispeed > 1){ispeed = ispeed-1;}
  }
    delay(ispeed);
...
    if(ispeed > 1){ispeed = ispeed-1;}

I would expect them to blink faster as you are reducing the delay.

You might want to have a look at my Blinkenlight blog http://blog.blinkenlight.net. If you want to blink 20 LEDs or less this is the place to go. Although by now I have one experiment where I blink 80 LED :wink: