Help with score keeper

Hi Everyone,

I’m having a few issues with my circuit and hoping someone could help. I’ve uploaded a copy of the code, a picture of the circuit, and a picture from Tinkercad.

Issue 1:
I have three buttons:

  • left one increases the number on the display by one
  • middle resets number on display to zero
  • right one decreases the number on the display by one

In Tinkercad, my circuit and code work as desired but when I upload to the Uno, the decrease button actually resets the display to zero.

Issue 2:
When the number displayed is zero, it requires two pushes of the increase button

The file is a little slow to run on tinkercad, the delays help out some. I removed the delays when uploading to the Uno.

Thank you in advance for the help on my very first post.

single_digit_7_segment_with_buttons1.ino (3.8 KB)

Please read How to use this forum - please read how to post code (your code is small enough) and images.

I will ask a moderator to move this to a more suitable section as "installation and troubleshooting" is not meant for questions about your project.

the decrease button actually resets the display to zero.

I don’t think I’m surprised; the right button in your graphics connects to pin 11 which is the reset button according to your code.

OP’s ‘schematic’
single digit 7 segment with buttons.png

Anyone have the code to post ?

lastchancename:
Anyone have the code to post ?

/*    7 segment display layout

              A
            _____    
           |     | 
         F |     | B
           |__G__|        
           |     |
         E |     | C
           |_____|

              D  
*/



#define a 2
#define b 3
#define c 4
#define d 5
#define e 6
#define f 7
#define g 8

#define button1 9
#define button2 10
#define reset 11

int eb1;
int eb2;
int eb3;

int eab1;

int teamOneScore;

void setup(){
  
  pinMode(a,OUTPUT);
  pinMode(b,OUTPUT);
  pinMode(c,OUTPUT);
  pinMode(d,OUTPUT);
  pinMode(e,OUTPUT);
  pinMode(f,OUTPUT);
  pinMode(g,OUTPUT);
  
  pinMode(button1,INPUT_PULLUP);
  pinMode(button2,INPUT_PULLUP);
  pinMode(reset,INPUT_PULLUP);
  
  teamOneScore=0;
  
    digitalWrite(a,HIGH);
    digitalWrite(b,HIGH);
    digitalWrite(c,HIGH);
    digitalWrite(d,HIGH);
    digitalWrite(e,HIGH);
    digitalWrite(f,HIGH);
    digitalWrite(g,LOW);
}

void loop(){
  
  eb1=digitalRead(button1);     
  eb2=digitalRead(button2);
  eb3=digitalRead(reset);
  
  if(eb1==LOW && eab1==HIGH){
    teamOneScore++;
  }
  
  eab1=eb1;
  
  if (eb3==LOW && eab1==HIGH) {
    teamOneScore--;
    
  eab1=eb3;
    
  }
  
  if(eb2==LOW){
    teamOneScore=0;
  }
  
  switch (teamOneScore) {
    //zero
    case 1:
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, HIGH);
    digitalWrite(e, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, LOW);
    delay(200);
    break;
    
    //one
    case 2:
    digitalWrite(a, LOW);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, LOW);
    digitalWrite(e, LOW);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    delay(200);
    break;
    
    //two
    case 3:
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(c, LOW);
    digitalWrite(d, HIGH);
    digitalWrite(e, HIGH);
    digitalWrite(f, LOW);
    digitalWrite(g, HIGH);
    delay(200);
    break;
    
    //three
    case 4:
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, HIGH);
    digitalWrite(e, LOW);
    digitalWrite(f, LOW);
    digitalWrite(g, HIGH);
    delay(200);
    break;
    
    //four
    case 5:
    digitalWrite(a, LOW);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, LOW);
    digitalWrite(e, LOW);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    delay(200);
    break;
    
    //five
    case 6:
    digitalWrite(a, HIGH);
    digitalWrite(b, LOW);
    digitalWrite(c, HIGH);
    digitalWrite(d, HIGH);
    digitalWrite(e, LOW);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    delay(200);
    break;
    
    //six
    case 7:
    digitalWrite(a, LOW);
    digitalWrite(b, LOW);
    digitalWrite(c, HIGH);
    digitalWrite(d, HIGH);
    digitalWrite(e, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    delay(200);
    break;
    
    //seven
    case 8:
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, LOW);
    digitalWrite(e, LOW);
    digitalWrite(f, LOW);
    digitalWrite(g, LOW);
    delay(200);
    break;
    
    //eight
    case 9:
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, HIGH);
    digitalWrite(e, HIGH);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    delay(200);
    break;
    
    //nine
    case 10:
    digitalWrite(a, HIGH);
    digitalWrite(b, HIGH);
    digitalWrite(c, HIGH);
    digitalWrite(d, LOW);
    digitalWrite(e, LOW);
    digitalWrite(f, HIGH);
    digitalWrite(g, HIGH);
    delay(200);
    break;
    
    default:
    digitalWrite(a,HIGH);
    digitalWrite(b,HIGH);
    digitalWrite(c,HIGH);
    digitalWrite(d,HIGH);
    digitalWrite(e,HIGH);
    digitalWrite(f,HIGH);
    digitalWrite(g,LOW);
    
    teamOneScore=0;
    delay(200);
    break;
  }
}

Try moving
eab1=eb1; inside the if() block.
and why eab1=eb3;