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.
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.
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
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