Count problem and display

hello, can someone help me to display my count on a 4 digit 7 segment display?

  1. i have 2 sensor IR obstacle. It should decrease from a counter starting 3.
    2.When there are presence the counter should decrease.
    3.When both sensors sense a presence it should display zero.

Can someone correct this for me?

int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
int D1 = 9;
int D2 = 10;
int D3 = 11;
int D4 = 12;
int sensorA1 = 22; 
int sensorA2 = 23;
byte freeparking;
int isObstacle = HIGH;  // HIGH MEANS NO PRESENCE

void setup() {

  pinMode(pinA, OUTPUT);     
  pinMode(pinB, OUTPUT);     
  pinMode(pinC, OUTPUT);     
  pinMode(pinD, OUTPUT);     
  pinMode(pinE, OUTPUT);     
  pinMode(pinF, OUTPUT);     
  pinMode(pinG, OUTPUT);   
  
  pinMode(D4, OUTPUT);
  pinMode(sensorA1, INPUT);
  pinMode(sensorA2, INPUT);
 
  freeparking =3; 


  if (freeparking==0)
{
  digitalWrite(pinA, LOW);   
  digitalWrite(pinB, LOW);   
  digitalWrite(pinC, LOW);   
  digitalWrite(pinD, LOW);   
  digitalWrite(pinE, LOW);   
  digitalWrite(pinF, LOW);   
  digitalWrite(pinG, HIGH);

  digitalWrite(D4, HIGH); }
 else if ( freeparking ==1)

 {
  digitalWrite(pinA, HIGH);   
  digitalWrite(pinB, LOW);   
  digitalWrite(pinC, LOW);   
  digitalWrite(pinD, HIGH);   
  digitalWrite(pinE, HIGH);   
  digitalWrite(pinF, HIGH);   
  digitalWrite(pinG, HIGH);

  digitalWrite(D4, HIGH);
  }
 else if (freeparking ==2)

  {
  digitalWrite(pinA, LOW);   
  digitalWrite(pinB, LOW);   
  digitalWrite(pinC, HIGH);   
  digitalWrite(pinD, LOW);   
  digitalWrite(pinE, LOW);   
  digitalWrite(pinF, HIGH);   
  digitalWrite(pinG, LOW); 

  digitalWrite(D4, HIGH);
    }
}

void loop() {
 
isObstacle = digitalRead(sensorA1);
  if (isObstacle == LOW)
  {freeparking--;

   
  }
  else
  {
    freeparking++;
 
  }


/////////////////////////////////////

 isObstacle = digitalRead(sensorA2);
  if (isObstacle == LOW)
  {
   freeparking--;

  }
  else
  {
    freeparking++;
 
   
  }
 

}

Hi,
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks. Tom.. :slight_smile:

Can someone correct this for me?

What’s not working in your code?

Hi,
Why are you cross posting?

http://forum.arduino.cc/index.php?topic=540412.15

Tom... :slight_smile:

larryd:
What’s not working in your code?

My count on the 7 segment display is not decreasing nor increasing.

Have i well written and define my count?

Which part of the program updates the display with the count ?

UKHeliBob:
Which part of the program updates the display with the count ?

My counter is : freeparking =2

If my sensor sense a presence it should decrease the counter by 1 and if presence is gone it should increment by 1.

There are 2 IR sensor.

Im not able to link the count with the 7segment display.

My ' freeparking++ and freeparking -- ' is not being linked to the display.

what would be the proper way to link it with the display my count?

Put the code that displays the number in a function and call it when required