Beginner - basic button counter

Greetings! I am pretty new to Arduino and am taking on my first project. I took a mechatronics course in college so I do have limited experience with microcontrollers and programming, but I am still very inexperienced.

I have a much larger goal in mind (baseball scoreboard), but I thought I’d take it slow and start with some basics.

I am hoping to find some help in creating a basic counter connected to a 7 segment display. Start at zero, each time the button is pressed, add 1 to the display. For simplicity’s sake, it would probably be easiest to reset the counter to 0 after it shows 9 and the button is pressed again. (However, as I get further, I will be using cascading counters, I believe. For example, imagine I am counting outs in an inning, starting with 0. The button is pressed once, the display shows 1 out. Pressed again, the display shows 2 outs. Pressed one more time, it reset the outs to zero and advances the inning.)

I understand some of the basic flow-chart nature of programming, I just really struggle with the syntax.

I have been looking through Arduino tutorials and replicated the following push button program:

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
 // initialize the LED pin as an output:
 pinMode(ledPin, OUTPUT);
 // initialize the pushbutton pin as an input:
 pinMode(buttonPin, INPUT);
}

void loop() {
 // read the state of the pushbutton value:
 buttonState = digitalRead(buttonPin);

 // check if the pushbutton is pressed.
 // if it is, the buttonState is HIGH:
 if (buttonState == HIGH) {
   // turn LED on:
   digitalWrite(ledPin, HIGH);
 } else {
   // turn LED off:
   digitalWrite(ledPin, LOW);
 }
}

I was also able to replicate the following display/counter:

int num_array[10][7] = {  { 1,1,1,1,1,1,0 },    // 0
                         { 0,1,1,0,0,0,0 },    // 1
                         { 1,1,0,1,1,0,1 },    // 2
                         { 1,1,1,1,0,0,1 },    // 3
                         { 0,1,1,0,0,1,1 },    // 4
                         { 1,0,1,1,0,1,1 },    // 5
                         { 1,0,1,1,1,1,1 },    // 6
                         { 1,1,1,0,0,0,0 },    // 7
                         { 1,1,1,1,1,1,1 },    // 8
                         { 1,1,1,0,0,1,1 }};   // 9
                                      
//function header
void Num_Write(int);

void setup() 
{ 
 // set pin modes
 pinMode(2, OUTPUT);   
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 

}

void loop() 
{
 
 //counter loop
 
 for (int counter = 10; counter > 0; --counter) 
 {
  delay(1000);
  Num_Write(counter-1); 
 }
 delay(3000);
}

// this functions writes values to the sev seg pins  
void Num_Write(int number) 
{
 int pin= 2;
 for (int j=0; j < 7; j++) {
  digitalWrite(pin, num_array[number][j]);
  pin++;
 }
}

Could someone please help me work through a simple pushbutton counter? I think the array could be helpful with outputting to the display. I feel like I should start from the code directly above, but instead of simply starting at 9 and counting down every second, I would need to include a line where the pushbutton pin is read, and if it is high it advances the counter by one.

Thanks for any help!!

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Then tell us what your programs actually do and what you want them to do differently.

…R

The first program turns on an LED (built in to pin 13) with the push of a button (coded as pin 2). If the button state is not read as high, the light turns off.

The 2nd program is more in line with what I am trying to accomplish at the moment; it counts down from 9 to 0 and repeats.

More specifically, for my understanding, this program first creates/defines an array of 10 rows, 7 figures wide. Within the brackets is the high/low command to each of the (pins) segments of a 7-segment display, and they form the numbers 0 through 9 moving down the array. From this array, I now have a pre-determined set of high/low commands to create any digit 0-9

I do not know what the next line of code does. After that, we designate pins 2-8 to be digital output pins.

Now we have what seem to me to be 2 concurrently running loops; one is a counting loop, counting down from 9 to zero, and the other must be telling pins 2-8 what to do based on the counting that happened above. The actual syntax at this point is getting to be above what I know at this moment, but I think I understand the basics of what is happening.

I would like this program to not run a counting loop, but instead have the value increase by one as the result of a button being pressed. I think the lower loop of code could stay relatively intact if, as I think, it is simply evaluating the result of the loop above it and producing the corresponding 0-9 digit using the array.

I know this is very basic, but am I on the right track?

For clarity, here is my end goal:

Create a baseball scoreboard using push buttons, 7-segment displays, and regular LED components. The scoreboard will display home and visitor's scores, the inning (including top/bottom), and the location of baserunners (just like the graphics on a TV broadcast).

There will be individual buttons (4) for "single", "double", "triple", and "homerun", and these buttons are what will control the LEDs corresponding with baserunner position. They will also lead to basic arithmetic being performed to increase the score appropriately.

There will be another button for "out" which, upon reaching 3, will clear the bases and adjust top/bottom, which will in turn adjust the inning (if necessary) and whose turn it is to score.

With that said, I am trying to break this down into (very) small chunks that I can build upon. Thank you!

So 6 digits for scores & inning, and up to 8 other LEDs? Can use a single MAX7219 to control 5V powered common cathode displays and individual LEDs connected up like a digit but with 4 of the LEDs physically placed in a diamond, and 3 others indicating how many outs, and maybe two indicating top and bottom of the inning - those could come from the unused decimal points of the digits.
I offer a MAX7219 breakout board to wire that up easily, connect it to an Uno for its inputs, wire directly to the displays & LEDs. Connect your buttons to the Uno.
http://www.crossroadsfencing.com/BobuinoRev17/

If you need higher voltage displays, like 12V and multiple LEDs in series per digit, I offer a card that can drive up to 12 common anode digits or a mix of digits and LEDs, it has a 328P on it you can connect your buttons as well. Plug on a FTDI Basic for code downloading.

ragincajun019:
I would like this program to not run a counting loop, but instead have the value increase by one as the result of a button being pressed.

I suspect all you need to do is replace the FOR loop with some code that increments the variable counter every time you press your button. Note that you have to check that the button is released and then pressed. Something like this pseudo code

previousButtonState = currentButtonState;
currentButtonState = digitalRead(buttonPin);
if (previousButtonState == HIGH and currentButtonState == LOW) { // assumes LOW = pressed
   counter ++;
}

...R

I apologize for my ignorance, but I can’t seem to successfully write that code into a program. I know you said it is psuedo-code, but I’m not sure how to turn it into actual code.

Starting with this program:

int num_array[10][7] = {  { 1,1,1,1,1,1,0 },    // 0
                         { 0,1,1,0,0,0,0 },    // 1
                         { 1,1,0,1,1,0,1 },    // 2
                         { 1,1,1,1,0,0,1 },    // 3
                         { 0,1,1,0,0,1,1 },    // 4
                         { 1,0,1,1,0,1,1 },    // 5
                         { 1,0,1,1,1,1,1 },    // 6
                         { 1,1,1,0,0,0,0 },    // 7
                         { 1,1,1,1,1,1,1 },    // 8
                         { 1,1,1,0,0,1,1 }};   // 9
                                      
//function header
void Num_Write(int);

void setup() 
{ 
 // set pin modes
 pinMode(2, OUTPUT);   
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 

}

void loop() 
{
 
 //counter loop
 
 for (int counter = 10; counter > 0; --counter) 
 {
  delay(1000);
  Num_Write(counter-1); 
 }
 delay(3000);
}

// this functions writes values to the sev seg pins  
void Num_Write(int number) 
{
 int pin= 2;
 for (int j=0; j < 7; j++) {
  digitalWrite(pin, num_array[number][j]);
  pin++;
 }
}

I erased the “counter” FOR loop and tried to replace with the IF loop you mentioned. Here’s my attempt to rewrite the program such that it increments the variable counter by 1 with the press of a button as opposed to a continuous counting loop:

// make an array to save Sev Seg pin configuration of numbers

int num_array[10][7] = {  { 1,1,1,1,1,1,0 },    // 0
                          { 0,1,1,0,0,0,0 },    // 1
                          { 1,1,0,1,1,0,1 },    // 2
                          { 1,1,1,1,0,0,1 },    // 3
                          { 0,1,1,0,0,1,1 },    // 4
                          { 1,0,1,1,0,1,1 },    // 5
                          { 1,0,1,1,1,1,1 },    // 6
                          { 1,1,1,0,0,0,0 },    // 7
                          { 1,1,1,1,1,1,1 },    // 8
                          { 1,1,1,0,0,1,1 }};   // 9
                                       
//function header
void Num_Write(int);


int currentButtonState = LOW;		//initialize the button as "low"
int previousButtonState = currentButtonState;		//initialize previous button state as "low"



void setup() 
{ 
  // set pin modes
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(12, INPUT);
  
  
 
  int currentButtonState = digitalRead(12);	//current button state is whatever the button shows
  
  
}

void loop() 
{
  
  int counter = 0;
    if (previousButtonState == HIGH and currentButtonState == LOW){
    counter++;
  }
  
  
}


// this functions writes values to the sev seg pins  
void Num_Write(int number) 
{
  int pin= 2;
  for (int j=0; j < 7; j++) {
   digitalWrite(pin, num_array[number][j]);
   pin++;
  }
}

The code compiles fine, but nothing happens when I run it and press the button. Additionally, the program seems to run extremely slow - is there something in there eating up memory?

You don't have any code to read the state of the button :slight_smile:

Or maybe the last line in setup() should really be in loop().

You are also missing the line that updates previousButtonState

AND ... because you already have a variable called currentButtonState defined at the top of the program you MUST NOT have "int" at the start of that line as it will, confusingly, create another variable with the same name. Then the logic won't work.

...R

I made some minor adjustments but still no success. I removed the “int” from the line in the setup() and moved that line of code down to the loop(). Within the loop I added a line updating the previousButtonState which reads “previousButtonState = currentButtonState;”. Does the line “currentButtonState = digitalRead(12);” need to happen within the if loop?

I’m also confused about 3 lines up from that. I have “int counter = 0;”. Is this telling the program that the variable “counter” has an initial value of zero? Or is it defining the variable as being pin 0?

Also, I still don’t understand what is happening in the Num_Write(int number) section at the bottom. (I suppose I’m also confused about the Num_Write(int) which appears near the top, after the array). Those lines of code at the bottom remain untouched from the public program I started from. My hope was that this section of code simply writes a display to the 7-segment-display based on the logic happening above.

Thank you for helping me work through these baby steps, painful as it must be for someone who knows what they’re doing.

// make an array to save Sev Seg pin configuration of numbers

int num_array[10][7] = {  { 1,1,1,1,1,1,0 },    // 0
                          { 0,1,1,0,0,0,0 },    // 1
                          { 1,1,0,1,1,0,1 },    // 2
                          { 1,1,1,1,0,0,1 },    // 3
                          { 0,1,1,0,0,1,1 },    // 4
                          { 1,0,1,1,0,1,1 },    // 5
                          { 1,0,1,1,1,1,1 },    // 6
                          { 1,1,1,0,0,0,0 },    // 7
                          { 1,1,1,1,1,1,1 },    // 8
                          { 1,1,1,0,0,1,1 }};   // 9
                                       
//function header
void Num_Write(int);


int currentButtonState = LOW;		//initialize the button as "low"
int previousButtonState = currentButtonState;		//initialize previous button state as "low"



void setup() 
{ 
  // set pin modes
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(12, INPUT);
  
  
 
 
  
  
}

void loop() 
{
  
  currentButtonState = digitalRead(12);		//current button state is whatever the button shows
  int counter=0;
    if (previousButtonState == HIGH and currentButtonState == LOW){
    counter++;
      previousButtonState = currentButtonState;
  }
  
  
}


// this functions writes values to the sev seg pins  
void Num_Write(int number) 
{
  int pin= 2;
  for (int j=0; j < 7; j++) {
   digitalWrite(pin, num_array[number][j]);
   pin++;
  }
}

I overlooked the fact that your variable counter also needs to be a global. As the code is written now every time loop() repeats it will be reset to 0.

Another option is

  currentButtonState = digitalRead(12);		//current button state is whatever the button shows
  static int counter=0;
    if (previousButtonState == HIGH and currentButtonState == LOW){
    counter++;
      previousButtonState = currentButtonState;
  }

The word “static” tells the compiler to retain the value from the previous iteration.

The Num_Write() functions takes a number as an input and then displays the pattern associated with that number.

The array num_array has a set of data points for each number

If that is not a sufficient explanation please say so.

…R

I do understand that the array is a set of high/low commands which display the corresponding number on the 7-segment display. I assumed that the Num_Write() takes the integer that was calculated in the preceding IF loop and and writes that number to the display using the array.

There are 2 glaring issues when I run this program:

First, I do not get any output whatsoever from the 7-segment display; I would at least expect it to display “0” but none of the segments are illuminating.

Second, the program runs incredibly slow. I am using the electronics lab on circuits.io and the timer showing the program duration runs much slower than with other programs. Have I written code in such a manner that it is extremely slow to process? It seems like this should be a piece of cake for the Arduino Uno to handle.

I tried updating my program to include the line you mentioned last post, but still nothing changes. I feel like I’m trying to write a sonnet in Spanish but only know the words “donde está el baño”! I’m sorry I just don’t seem to be able to work through this - I don’t want to give up, but I may have overestimated my ability to pick this stuff up.

// make an array to save Sev Seg pin configuration of numbers

int num_array[10][7] = {  { 1,1,1,1,1,1,0 },    // 0
                          { 0,1,1,0,0,0,0 },    // 1
                          { 1,1,0,1,1,0,1 },    // 2
                          { 1,1,1,1,0,0,1 },    // 3
                          { 0,1,1,0,0,1,1 },    // 4
                          { 1,0,1,1,0,1,1 },    // 5
                          { 1,0,1,1,1,1,1 },    // 6
                          { 1,1,1,0,0,0,0 },    // 7
                          { 1,1,1,1,1,1,1 },    // 8
                          { 1,1,1,0,0,1,1 }};   // 9
                                       
//function header
void Num_Write(int);


int currentButtonState = LOW;		//initialize the button as "low"
int previousButtonState = currentButtonState;		//initialize previous button state as "low"



void setup() 
{ 
  // set pin modes
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(12, INPUT);
  
  
 
 
  
  
}

void loop() 
{
  
  currentButtonState = digitalRead(12);		//current button state is whatever the button shows
  static int counter=0;
    if (previousButtonState == HIGH and currentButtonState == LOW){
    counter++;
      previousButtonState = currentButtonState;
  }
  
  
}


// this functions writes values to the sev seg pins  
void Num_Write(int number) 
{
  int pin= 2;
  for (int j=0; j < 7; j++) {
   digitalWrite(pin, num_array[number][j]);
   pin++;
  }
}

When does Num_Write() ever get called? I don’t see in setup() or in loop().
You’re also using a ton of memory for the digits.
I would store each digit as a byte, and send the appropriate bits out.

byte numArray[] = {
0b01111110, // 0 with DB-a-b-c-d-e-f-g
0b00110000, // 1
// etc
0b01110011, // 9
}; // 10 byte vs 140 bytes

Then to write them out you are using PORTD bits 7-2 and PORTB bit 0

byte maskArray[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40,};

then when it’s time for an update:

for (x=0; x<7; x=x+1){
  if ((numArray[value] & maskArray[x]) == 0){
  digitalWrite (x+2), LOW);
  }
  else {
  digitalWrite (x+2, HIGH);
  }
}

Thank you for being willing to offer some help as well. I think I can follow what’s happening with that array and fill in the gaps.

I don’t really understand what’s happening with the following line:

byte maskArray[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40,};

Nor do I quite follow the FOR loop

for (x=0; x<7; x=x+1){
  if ((numArray[value] & maskArray[x]) == 0){
  digitalWrite (x+2), LOW);
  }
  else {
  digitalWrite (x+2, HIGH);
  }
}

I’m very good at math so it’s mostly a matter of not being able to interpret the syntax and specific commands in there.

Here’s how I understand that chunk:

Set “x” equal to zero. Then test to see if x<7. If true, add 1 to the previous value of “x”. Go to the next line. I start to get lost after that.

The IF loop says if the statement in the parenthesis is true, do the next line; otherwise, do the line below. And I understand the function of digitalWrite, but not as it’s written.

Also, Num_Write gets called out - in both the original program and my modified version - immediately after the array and before void setup(). It appears as “Num_Write(int);”.

It appears again after void loop() and shows up as “Num_Write(int number)”.

You define/declare Num_Write before setup(), that’s just part of creating it.
You define what it does with the function that is after loop().
There is no Num_Write(number) within loop() to actually use it.

The for loop uses the maskArray to look at each bit from numArray to decide whether to set an output Low or High.
It loops from 0 to 6.
So for maskArray[0] for example, the data is 0x01, or 0b00000001.
The code then performs a logical AND ( 0 & 0 = 0, 0 & 1 = 0, 1 & 0 = 1, 1 & 1 = 1).
So if numArray[value] has the value 0b01110011 and say x was up to 4, then:
01110011
& 00010000

= 00010000
that is not 0, so the output will digitalWrite ((4+2), HIGH);

The for loop has this syntax: for (starting state; end state; update state)
starting state: x = 0
end state: stop when x is no longer <7
update state: every time the for loop repeats, add 1 to x.
“update state” could be adding 1,2,3, subtracting, shifting a byte left or right, pretty much any math operation.
Same with “end state”: <, <=, >, >=, ==, != etc.
starting state of x = 0 works well with arrays as array index goes from 0 up to the number of elements in the array.
A 10 element array will accessed as array[0] to array[9].
The pins used are 2 to 8 tho, so adding 2 to the index (x in this case) lines up the digitalWrite with the pins being used.

pinsArray[x] 
could have been used as well if
byte pinsArray[] = {2,3,4,5,6,7,8,};

had been defined.

The 2nd program in the Original Post has this

for (int counter = 10; counter > 0; --counter)
 {
  delay(1000);
  Num_Write(counter-1);
 }
 delay(3000);

where the function Num_Write() is called with the number of the digit to display.

Your program in Reply #10 is missing an equivalent line.

You need to see the suggestions I made in the context of that program in the Original Post - I did not attempt to produce a complete piece of code for you.

…R

I see now that the “Num_Write()” is missing, as you said. It must have gotten lost when I was attempting to turn that FOR loop - which counts down from 9 to zero and repeats - into an IF loop that counts up incrementally if the button is pressed. I adjusted the code but still get the same non-results.

Thank you for your patience, but I do admit that I am getting a little bit lost. I can’t believe I am having this much difficulty performing such a simple task.

I understand you were not trying to write actual code for me, just pseudo-code. However, I have a tough time distinguishing between the two.

For instance, in this section from reply #9

  currentButtonState = digitalRead(12);		//current button state is whatever the button shows
  static int counter=0;
    if (previousButtonState == HIGH and currentButtonState == LOW){
    counter++;
      previousButtonState = currentButtonState;
  }

is there any part that is not truly code? I assume the “HIGH” and “LOW” commands are being properly used.

Additionally, in this section from reply #5

previousButtonState = currentButtonState;
currentButtonState = digitalRead(buttonPin);
if (previousButtonState == HIGH and currentButtonState == LOW) { // assumes LOW = pressed
   counter ++;
}

which parts are not truly code to be processed?

I’m sorry to ask you to spell it out for me, and I completely understand why you don’t simply write the program for me (because then I’ll never learn!), as simple as it may be. But I really do appreciate your help and would love to be able to work through this and find a working solution.

At this point, would I be better starting from scratch or continuing to modify my most recent code (below)?

// make an array to save Sev Seg pin configuration of numbers

byte numArray[] = {
  
  0b01111110, // 0 with DB-a-b-c-d-e-f-g
  0b00110000, // 1
  0b01101101, // 2
  0b01111001, // 3
  0b00110011, // 4
  0b01011011, // 5
  0b01011111, // 6
  0b01110000, // 7
  0b01111111, // 8
  0b01110011, // 9
}; 						// 10 byte vs 140 bytes


byte maskArray[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40,};

//function header



int currentButtonState = LOW;		//initialize the button as "low"
int previousButtonState = currentButtonState;		//initialize previous button state as "low"



void setup() 
{ 
  // set pin modes
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(12, INPUT);
  
  
 
 
  
  
}

void loop() 
{
  
  currentButtonState = digitalRead(12);		//current button state is whatever the button shows
  static int counter=0;
    if (previousButtonState == HIGH and currentButtonState == LOW){
    counter++;
      previousButtonState = currentButtonState;
    }
  
      
  delay(500);
  Num_Write(counter-1);

  
  
}


// this functions writes values to the sev seg pins  
void Num_Write(int number) 
{
  int pin= 2;
  int x=0;
  for (x=0; x<7; x=x+1){
  if ((numArray[number] & maskArray[x]) == 0){
  digitalWrite (x+2, LOW);
  }
  else {
  digitalWrite (x+2, HIGH);
  }
  }
}

Thank you.

Your program seems OK to me. You have not told us what it actually does.

I wonder if it should be

Num_Write(counter-1);

or

Num_Write(counter);

You probably also need a few lines to keep counter in range - something like this. Also printing the value so you can see what happens is a good idea

void loop()
{
 currentButtonState = digitalRead(12); //current button state is whatever the button shows
  static int counter=0;
    if (previousButtonState == HIGH and currentButtonState == LOW){
    counter++;
      previousButtonState = currentButtonState;
    }
   if (counter > 9) {
      counter = 0;
   }
   Serial.print("Counter "); Serial.println(counter);
     
  delay(500);
  Num_Write(counter-1);
}

And, yes, you are correct. The two snippets I posted will probably compile OK. I think they are functionally identical.

...R

I have not yet addressed the 2nd half of your last post, but I did change the line

Num_Write(counter-1);

to

Num_Write(counter);

and some of the segments light up. It does not show a number, but instead basically an upside-down capital “A” (all segments but the top are lit up). Additionally, the button doesn’t seem to make anything change.

As for telling you what the program actually does, pardon my ignorance but are you looking for like a line-by-line description by me about what I think is happening with each line of code?

This is what the program currently looks like:

// make an array to save Sev Seg pin configuration of numbers

byte numArray[] = {
  
  0b01111110, // 0 with DB-a-b-c-d-e-f-g
  0b00110000, // 1
  0b01101101, // 2
  0b01111001, // 3
  0b00110011, // 4
  0b01011011, // 5
  0b01011111, // 6
  0b01110000, // 7
  0b01111111, // 8
  0b01110011, // 9
}; 						// 10 byte vs 140 bytes


byte maskArray[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40,};

//function header



int currentButtonState = LOW;		//initialize the button as "low"
int previousButtonState = currentButtonState;		//initialize previous button state as "low"



void setup() 
{ 
  // set pin modes
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(12, INPUT);
  
  
 
 
  
  
}

void loop() 
{
  
  currentButtonState = digitalRead(12);		//current button state is whatever the button shows
  static int counter=0;
    if (previousButtonState == HIGH and currentButtonState == LOW){
    counter++;
      previousButtonState = currentButtonState;
    }
  
      
  delay(500);
  Num_Write(counter);

  
  
}


// this functions writes values to the sev seg pins  
void Num_Write(int number) 
{
  int pin= 2;
  int x=0;
  for (x=0; x<7; x=x+1){
  if ((numArray[number] & maskArray[x]) == 0){
  digitalWrite (x+2, LOW);
  }
  else {
  digitalWrite (x+2, HIGH);
  }
  }
}

ragincajun019:
As for telling you what the program actually does, pardon my ignorance but are you looking for like a line-by-line description by me about what I think is happening with each line of code?

No. I just meant you to describe what happens when you run the program.

If the parts are not lighting correctly then try a simple program that just calls numWrite(1) or numWrite(2) - without any user input.

IMHO the golden rule for debugging is simplify

You can also get funny displays if the program is running so fast that you don't have time to view each character.

...R