My loop doesnt loop :-(

Hi all, brand new to Arduino (Used to play with Picaxe, so not totally clueless in general terms) and am trying out basic simple interfaces, and one doesn't work

Using the 4 digit lcd code example from the download, it says in the manual it will count from 1 - 255. Well, it changes, but doesn't count properly. It displays 1111, 2222, 3333, 44444, etc. When it gets to 9999 it then starts displaying apparently random blocks of LED segments, then reverts to 1111, 2222.

So, I tried my own to see what happens. I wrote this code ;-

int latch = 9; //74HC595  pin 9 STCP
int clock = 10; //74HC595  pin 10 SHCP
int data = 8; //74HC595  pin 8 DS

void setup() {
  pinMode(latch, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(data, OUTPUT);
}
void loop() {
  digitalWrite(latch, LOW);
  shiftOut(data, clock, LSBFIRST, 45);
  delay(1000);
  shiftOut(data, clock, LSBFIRST, 128);
  delay(1000);
  digitalWrite(latch, HIGH);
}

When I upload it, the display clears, then dispays some LED segments - as defined by '45' I assume - for 1 second, then displays a different segment pattern (128?) but hangs there. It should disply it for one second then go back to 45.

What is wrong with my loop?

And how do I send an actual character or set of characters to the LCD?

Thanks,
Richard

What happens if you put a Serial.println( " I did do a loop " ); after the digitalWrite(latch, HIGH); on the serial monitor?

You can use a library someone else wrote to send characters to the LCD or you can write your own library.

Try this for loop()

void loop() 
{
  //count up routine
  for (int j = 0; j < 256; j++) 
   {
    //ground latchPin and hold low for as long as you are transmitting
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, j);
    //return the latch pin high to signal chip that it
    //no longer needs to listen for information
    digitalWrite(latchPin, HIGH);
    delay(1000);
  }
}

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:

I continue to be confused. Adding the println() code, the serial monitor shows that the software is indeed looping.

However, the LCD still shows the second set of segments with no change. If I change the values, it displays the first set for a second, then the second set, but stays on the second set.

Using the code with the incremental value of j from above, it changes for each value of j. (And if I println j to the monitor, it shows it incrementing.

I can’t see why the display doesn’t flip back and forth in my code.

void loop() {
  digitalWrite(latch, LOW);
  shiftOut(data, clock, LSBFIRST, 45);
  digitalWrite(latch, HIGH);  
  delay(1000);
  digitalWrite(latch, LOW);
  shiftOut(data, clock, LSBFIRST, 128);
  digitalWrite(latch, HIGH);  
  delay(1000);
}

Thank you, Larry, that works. The problem now is "Why does it work?"

If the latch is low shouldn't it still be open for the next shiftOut until we set it high? Why does setting it to high then back to low 'reopen' the chip to receive the next input?

Back to the reference, I guess :frowning:

Richard