how to show value at the beginning rather than after the value is changing

greetings folks, so lets get to the point
i have an issue of my arduino, i’m making the ‘flight cycle counter’ with sharp IR sensor that will count if the sensor value is =400, i want to make the current value is shown at the beginning, not after i sense the sensor because at the beginning the value is none (nothing appeared) but if the sensor is sense something, the value will appear at 0 instead of 1, so heres the code

// Enable this line if using Arduino Uno, Mega, etc.
#include <LiquidCrystal.h>
#include <EEPROM.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


const int sensorPin = A0; //analog pin 0
const int ledPin = 13;  // the pin that the LED is attached to

// vars
int sensorCounter = 0;   // counter for the number of button presses
int sensorState = 0;     // current state of the sensor
int lastSensorState = 0;

void setup() {
  // initialize the sensor pin and input
  pinMode(sensorPin, INPUT);
  // initialize the LED as an output
  pinMode(ledPin, OUTPUT);
  // initialize serial communication
  Serial.begin(9600);
  
// set the matrix 
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Flight Cycle :");
  sensorCounter = EEPROM.read(0);
  EEPROM.write (0,0);
  }


void loop() {
  // read the sensor input pin:

  sensorState = analogRead(sensorPin);

  // if sensor is closer than than x distance
  if (sensorState == 400 ) {
    sensorCounter++;
    EEPROM.write(0, sensorCounter);
    lcd.clear();
    delay(50);    
    lcd.setCursor(0,0);
    lcd.print("Flight Cycle :");
    lcd.setCursor(0,1);
    lcd.print(sensorCounter / 2);
   
    // show output on the digital display
      if (sensorCounter % 2 == 0) {
    digitalWrite(ledPin, HIGH);
  } else {
   digitalWrite(ledPin, LOW);
    // slow down the output
    delay(2000);
  } 

  }
  // turns on the LED every ten counts 

  }

i think thats it for now, thank you if you will notice and help me. ill appreciate it :slight_smile:

You REALLY need to properly indent your code. Tools + Auto Format makes it so simple.

i want to make the current value is shown at the beginning

Shown where? At the beginning of what?

but if the sensor is sense something, the value will appear at 0 instead of 1

I have no idea what this means.

  if (sensorState == 400 )That seems a very exact number to look for. What range of values does the sensor return ?

    EEPROM.write(0, sensorCounter);What will happen when the count is larger than 255 ?

@matramp is probably solving too many issues at a time :slight_smile: In another thread he/she was already pointed to the use of put and get.