using Max6971 and 16 led array

Hello, I am new to all this, I have a project that is using the Max6971 chip with 16 led’s connected to it, I want to light all of the led’s and then with the push of a button turn off one led per button push, I have looked at many examples and now I am more confused, I found this line of code will write all of the led’s
for (int numberToDisplay = 511; numberToDisplay;)
and this is the line I tried to use to turn off one led at a time with the button press
for (int i = 0; i < numberToDisplay; i–);
I am not sure what is going on here and need some help, here is the code so fare

#include <TimerOne.h>

int buttonPin = 12;
int buttonState = 0;

int latchPin = 4;
int clockPin = 3;
int dataPin = 2;
int pwmPin = 10;

//int shiftOut(latchPin, dataPin, clockPin, NofRegisters);

void setup() {
// set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(10, OUTPUT);

Timer1.pwm(9, 1010);
void callback()
digitalWrite(10, digitalRead(10) ^ 1);

void loop()
for (int numberToDisplay = 511; numberToDisplay;)
if (digitalRead(buttonPin) == LOW)
for (int i = 0; i < numberToDisplay; i–);

digitalWrite(latchPin, LOW);
// shift out the bits:

shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
// take the latch pin high so the leds will light up:
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);

// pause before next value:



Where is the 3rd part of this line? The part that tells it how to change the value of numberToDisplay? for (int numberToDisplay = 511; numberToDisplay;)

What are these meant to do? Timer1.initialize(500); Timer1.pwm(9, 1010); Timer1.attachInterrupt(callback);

as you don't seem to have an Interrupt Service Routine that does anything.

Pricey part, single resistor to set current limit for all 16 outputs is nice.

Hi all I need help with some code , I have a 16 led array that is controlled with a Max6971, all 16 leds are connected to the Max6971, this is a game my son designed the game starts with all of the leds on and when the button is pressed the last led goes out, each time the button is pressed one more led goes out, the led array is a life bar for the game that my son designed. I need help with this control, how do you count down on the array one led at a time, I have seen many examples but I don’t know how to code this array, I have built the two game controllers the hardware is good to go, I need help with the code, can someone help me get going with some code to control this led array as described, I would post the code that I have tried to write but it does not work, the game has a digital dice that works fine but the life bar is not working, I used two 328 chips because the game controller was developed at different time than the life bar, here is the diagram for the game controller. Thanks

HI all I did not want anyone to write the code for me , I just need some one to point me in the correct direction, after all is this not what this forum is all about, so can some one please help me with this, how about the guy that goes by the name CrossRoads, you seem to have a handle on the code, if not him then some one. Thanks. Keith

Make an array with the data you want to send out, and cycle thru it.

// 0b1111 = F, 0b1110 = E, 0b1100 = C, 0b1000 = 8, 0b0000 = 0
int ledOutArray[] = {0xFFFF, 0xFFFE, 0xFFFFC, 0xFFF8, 0xFFF0, 0xFFE0, 0xFFC0, 0xFF80, 0xFF00, 0xFE00, 0xFC00, 0xF800, 0xF000, 0xE000, 0xC000, 0x8000, 0x0000,};
byte x = 0;
// increment x somehow for the game, then send data out
digitalWrite (lePin, LOW);
shiftOut (dataPin, clockPin, MSBFIRST, highByte (ledOutArray[x]); // send out upper 8 bits
shiftOut (dataPin, clockPin, MSBFIRST, lowByte (ledOutArray[x]); // send out lower 8 bits
digitalWrite (lePin, HIGH);

Thank you I will give that a go, it looks neat and It is good to get some new direction to go. The more I look at the more it makes sense.Thanks Keith