7 segment and Push Button Display Letters

Hi, I'm trying to create a program where it displays "AbC" one at a time. For every keypress of button 1 it should cycle from A->b->C and go back to A. For button 2, it is the opposite of button 1, from C->b ->A. button 1 and button 2 can be pressed anytime. For example, If the current display is “A” pressing button 2 would display “C” then pressing button 1 will display it back to “A” and so forth. Button 3 is used to blank the display and reset the operation.

The problem that I encounter is that when I press the button 1 it will cycle only once through Abc then it will not cycle again it is just stuck to last letter and won't change and same for the button 2..And also I cant change the letter if I press between button 1 and button 2

5-5 CODES.txt (2.17 KB)

More members will see your code if posted properly. Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.

int pins[] = {12, 11, 10, 9, 8, 7, 6};
int buttonINP[] = {A0, A1, A2};
int i = 0;
int j = 0;



int sevState = 0; //Start Blank Display
int sevState1 = 0;
int sevState2 = 0;

int buttonOldA0 = 1; 
int buttonNewA0;

int buttonOldA1 = 1;
int buttonNewA1;

int buttonOldA2 = 1;
int buttonNewA2;



void displayLetter( int value)
{
   
  digitalWrite(12, bitRead(value,6)); 
  digitalWrite(11, bitRead(value,5)); 
  digitalWrite(10, bitRead(value,4)); 
  digitalWrite(9, bitRead(value,3));  
  digitalWrite(8, bitRead(value,2));  
  digitalWrite(7, bitRead(value,1));  
  digitalWrite(6, bitRead(value,0));  
  
}  




void setup()
{
  for(i=0; i<7; i++)
  {
   pinMode(pins[i], OUTPUT);
  }
  for(j=0; j<4; j++)
  {
   pinMode(buttonINP[j], INPUT);
  }
   
}


void loop()
{
  
  buttonNewA0 = digitalRead(A0);
  buttonNewA1 = digitalRead(A1);
  
  if(buttonOldA0 == 0 && buttonNewA0 ==1)
  {
  		if(sevState1 == 0)
        {
         			//abcdefg C
     	displayLetter(B1001110);
        sevState1 = 1;
    
        }
    
    	else if (sevState1 == 1)
        {
        			 //abcdefg b
     	displayLetter(B0011111);
        sevState1 = 2;
        }
    
    	else if (sevState1 == 2) 
        {
        			 //abcdefg A
     	displayLetter(B1110111);;
        sevState = 3;
        }
  
  }
  
  buttonOldA0 = buttonNewA0;
  
  
  
  
  
  if(buttonOldA1 == 0 && buttonNewA1 ==1 && buttonOldA0 == 1)
  {
  		if(sevState1 == 0)
        {
         			//abcdefg C
     	displayLetter(B1001110);
        sevState1 = 1;
    
        }
    
    	else if (sevState1 == 1)
        {
        			 //abcdefg b
     	displayLetter(B0011111);
        sevState1 = 2;
        }
    
    	else if (sevState1 == 2) 
        {
        			 //abcdefg A
     	displayLetter(B1110111);;
        sevState = 3;
        }
  
  }
  
  buttonOldA1 = buttonNewA1;
  
  
  
  
  
  
  if(buttonOldA2 == 0 && buttonNewA2 ==1)
  {
  		if(sevState2 == 0)
        {
         			 //abcdefg blank
     	displayLetter(B0000000);
        sevState = 1;
        }
    
  }
  
  buttonOldA2 = buttonNewA2;
 
}

My suggestion: First implement the function of button 1! The 3 codes for the characters (A, b, C) belong in an array that is addressed with an index 0 ... 2. The index must be extrapolated modulo 3.
If that works, do (almost) the same with button 2, the index must then be decremented and set back to 2 at -1.

Once you change sevState1 to 3 there is no 'if' statement to make that state do anything. Perhaps you should go back to sevState1=0; instead of sevState1=3;

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.