displaying the numbers of 2 digit 7 segment display to the serial monitor

so I am trying to display my 2 digits 7 segments display to the serial monitor. I want to display these numbers side by side but it is not working. I only can display one of these digits. I also want to save these as A B C and use them to do arithmetic operations.

sketch_oct12a.ino (5.21 KB)


Can you please post your code as explained in the forum guide in the sticky post so that those of us using phones and tablets can read it?

Also, please do not post images of serial monitor, just cut & paste the text into your post, using code tags.

Now the most important question: what are you trying to achieve and how are you doing it? Your question makes no sense to me. The serial monitor is not a 7 segment display.

int a1 = 4;
int a2 = 5;
int a3 = 6;
int a4 = 7;
//BCD 2
int b1 = 22;
int b2 = 23;
int b3 = 24;
int b4 = 25;
int switchUpPin = 8;
int switchDownPin2 = 9;
int counter = 0;
int counter2 = 0;
int buttonUpState = 0;
int lastButtonUpState = 0;
int buttonDownState2 = 0;
int lastButtonDownState2 = 0;
void setup()
{pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(22,OUTPUT);
pinMode(23,OUTPUT);
pinMode(24,OUTPUT);
pinMode(25,OUTPUT);
Serial.println("Hello World");
Serial.begin(9600);
}
void loop()
{
buttonUpState = digitalRead(switchUpPin);
buttonDownState2 = digitalRead(switchDownPin2);
if (buttonUpState != lastButtonUpState)
{
if (buttonUpState == HIGH || buttonDownState2 == HIGH)
{
//Reset the counter to -1
if(counter == 9 && counter2 ==9 )
{
counter = -1;
counter2 = -1;
}
//Increase the counter by 1
counter++;
counter2++;
//Print the counter to the console and calling the function

Serial.println(counter2, counter);
changeNumber(counter);
changeNumber2(counter2);
//Delaying by 250 ms
delay(250);
}
else
{
Serial.println("OFF");
}
//Delay to avoid button bouncing
delay(50);
}
// if (buttonDownState2 != lastButtonDownState2)
// {
// if (buttonDownState2 == HIGH)
// {
// //Reset the counter to -1
// if(counter2 == 9)
// {
// counter2 = -1;
// }
// //Increase the counter by 1
// counter2++;
// //Print the counter to the console and calling the function
// Serial.println(counter2);
// changeNumber2(counter2);
// //Delaying by 250 ms
// delay(250);
// }
// else
// {
// Serial.println("OFF");
// }
// //Delay to avoid button bouncing
// delay(50);
// }
changeNumber(counter);
changeNumber2(counter2);

}

void changeNumber(int buttonPress)
{
switch (buttonPress)
{
case 0://0000

digitalWrite(a1, LOW);
digitalWrite(a2, LOW);
digitalWrite(a3, LOW);
digitalWrite(a4, LOW);
break;
case 1://0001

digitalWrite(a1, HIGH);
digitalWrite(a2, LOW);
digitalWrite(a3, LOW);
digitalWrite(a4, LOW);
break;
case 2://0010

digitalWrite(a1, LOW);//0
digitalWrite(a2, HIGH);//1
digitalWrite(a3, LOW);//0
digitalWrite(a4, LOW);//0
break;
case 3://0011

digitalWrite(a1, HIGH);//1
digitalWrite(a2, HIGH);//1
digitalWrite(a3, LOW);//0
digitalWrite(a4, LOW);//0
break;
case 4://0100

digitalWrite(a1, LOW);//0
digitalWrite(a2, LOW);//0
digitalWrite(a3, HIGH);//1
digitalWrite(a4, LOW);//0
break;
case 5://0101

digitalWrite(a1, HIGH);//1
digitalWrite(a2, LOW);//0
digitalWrite(a3, HIGH);//1
digitalWrite(a4, LOW);//0
break;
case 6://0110

digitalWrite(a1, LOW);//0
digitalWrite(a2, HIGH);//1
digitalWrite(a3, HIGH);//1
digitalWrite(a4, LOW);//0
break;
case 7: //0111

digitalWrite(a1, HIGH);//1
digitalWrite(a2, HIGH);//1
digitalWrite(a3, HIGH);//1
digitalWrite(a4, LOW);//0
break;
case 8: //1000

digitalWrite(a1, LOW);//0
digitalWrite(a2, LOW);//0
digitalWrite(a3, LOW);//0
digitalWrite(a4, HIGH);//1
break;
case 9://1001

digitalWrite(a1, HIGH);//1
digitalWrite(a2, LOW);//0
digitalWrite(a3, LOW);//0
digitalWrite(a4, HIGH);//1
break;
// dont use IF, use Switch CASE
}
}
void changeNumber2(int buttonPress2)
{
switch (buttonPress2)
{
case 0://0000

digitalWrite(b1, LOW);
digitalWrite(b2, LOW);
digitalWrite(b3, LOW);
digitalWrite(b4, LOW);
break;
case 1://0001

digitalWrite(b1, HIGH);
digitalWrite(b2, LOW);
digitalWrite(b3, LOW);
digitalWrite(b4, LOW);
break;
case 2://0010

digitalWrite(b1, LOW);//0
digitalWrite(b2, HIGH);//1
digitalWrite(b3, LOW);//0
digitalWrite(b4, LOW);//0
break;
case 3://0011

digitalWrite(b1, HIGH);//1
digitalWrite(b2, HIGH);//1
digitalWrite(b3, LOW);//0
digitalWrite(b4, LOW);//0
break;
case 4://0100

digitalWrite(b1, LOW);//0
digitalWrite(b2, LOW);//0
digitalWrite(b3, HIGH);//1
digitalWrite(b4, LOW);//0
break;
case 5://0101

digitalWrite(b1, HIGH);//1
digitalWrite(b2, LOW);//0
digitalWrite(b3, HIGH);//1
digitalWrite(b4, LOW);//0
break;
case 6://0110

digitalWrite(b1, LOW);//0
digitalWrite(b2, HIGH);//1
digitalWrite(b3, HIGH);//1
digitalWrite(b4, LOW);//0
break;
case 7: //0111

digitalWrite(b1, HIGH);//1
digitalWrite(b2, HIGH);//1
digitalWrite(b3, HIGH);//1
digitalWrite(b4, LOW);//0
break;
case 8: //1000

digitalWrite(b1, LOW);//0
digitalWrite(b2, LOW);//0
digitalWrite(b3, LOW);//0
digitalWrite(b4, HIGH);//1
break;
case 9://1001

digitalWrite(b1, HIGH);//1
digitalWrite(b2, LOW);//0
digitalWrite(b3, LOW);//0
digitalWrite(b4, HIGH);//1
break;
// dont use IF, use Switch CASE
}
}

No. If you do not listen to what I ask, I am not willing to help you. I was nice and polite. You are breaking forum rules.

OK, now actually go and read the forum instructions, especially point 7, so that you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code" it can often become quite garbled and is always more difficult to read.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.