LCD to display cycles

here is my code

#include <LiquidCrystal.h>
int x;
int count = 0;  //initialize counter
LiquidCrystal lcd(1,2,4,5,6,7); //initialize LCD screen
int relayInput = 13; //initialize relay

void setup() {
pinMode(relayInput, OUTPUT);
digitalWrite(relayInput, HIGH);
lcd.begin(16,2);
lcd.print("Cycles:");
lcd.print(x);

}

void loop() {
  digitalWrite(relayInput, LOW);
  delay(1000);
  digitalWrite(relayInput, HIGH);
  delay(1000); 
  x = count++;
}

what i am trying to do is count every time the code runs through the void loop and display it on the LCD screen. What i feel is happening is that x is getting overwritten every time, or is maybe just not counting to begin with.

any help to this issue would be nice.

thank you

i have also tried this

#include <LiquidCrystal.h>
int x;
int count = 0;  //initialize counter
LiquidCrystal lcd(1,2,4,5,6,7); //initialize LCD screen
int relayInput = 13; //initialize relay

void setup() {
pinMode(relayInput, OUTPUT);
digitalWrite(relayInput, HIGH);
lcd.begin(16,2);
lcd.print("Cycles:");
//lcd.print(x);

}

void loop() {
  digitalWrite(relayInput, LOW);
  delay(1000);
  digitalWrite(relayInput, HIGH);
  delay(1000); 
  //x = count++;
  lcd.print(count++);
}

but the issue is that it displays increment numbers without replacing the previous number.

lcd.clearLine(2)?

The first program never prints anything.

The second program prints x but as you do not position the cursor before printing each value is printed alogside the previous one. Some investigation of the setCursor() function would seem to be required. See setCursor

UKHeliBob:
The first program never prints anything.

It prints once in setup. But never again, just counts up forever in its head.

UKHeliBob:
The first program never prints anything.

The second program prints x but as you do not position the cursor before printing each value is printed alogside the previous one. Some investigation of the setCursor() function would seem to be required. See setCursor

setting the cursor did the trick.

here's the final code for anyone who found this thread having the same issue

#include <LiquidCrystal.h>
int x;
int count = 0;  //initialize counter
LiquidCrystal lcd(1,2,4,5,6,7); //initialize LCD screen
int relayInput = 13; //initialize relay

void setup() {
pinMode(relayInput, OUTPUT);
digitalWrite(relayInput, HIGH);
lcd.begin(16,2);
lcd.print("Cycles:");
}

void loop() {
  digitalWrite(relayInput, LOW);
  delay(1000);
  digitalWrite(relayInput, HIGH);
  delay(1000); 
  lcd.setCursor(0,1);
  lcd.print(count++);
}
pinMode(relayInput, OUTPUT);

Kind of odd that you're using a pin named "relayInput" as an ouput.

Well done for getting it working. Here are some comments that I hope you will find helpful

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); //initialize LCD screen

It would be a good idea to get out of the habit of using pins 0 or 1 for anything other than Serial communication as they are used by the Serial interface. Not a problem in this program but could be if you want to use it in another one.

int relayInput = 13; //initialize relay

Would be better as

const byte relayOutput = 13; //initialize relay

const because it never changes in the program. byte because its value is less than 255 so it doesn't need to be an int and name changed to reflect its role as far as the Arduino is concerned.

 delay(1000);

The use of delay() in this program is acceptable as it is not doing anything else but in more complicated programs the fact that the entire program will freeze for one second could be unacceptable. Try adding an input that resets count to zero to see what I mean. Now, before you really need it, would be a good time to research the use of millis() for timing. See the BlinkWithoutDelay example, Using millis() for timing. A beginners guide and Several things at the same time