I am trying to make a game where there are arrows going towards an object (in this case I printed x) and you have to evade the arrows. When you press the button it is supposed to print x on the top row and clear the bottom row with printing nothing and if you don't press the button its supposed to print x on the bottom row and nothing on the top. Then the for loop is supposed to print arrows randomly going from right to left.
Problem: When I actually run the code I only see the x every time the arrow hits the (0,1) or (0,0) position.
I want the x to be there all the time.
#include <LiquidCrystal.h>
// init the lcd display according to the circuit
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
String line2 = " x ";
int xPosition;
int yPosition;
int yConstant;
void setup() {
lcd.begin(16, 2);
// put your setup code here, to run once:
int switchState = 0;
pinMode(7, INPUT);
int leftjump = 0;
pinMode(8, INPUT);
}
void loop() {
///////////////////////////////
//supose tp print arrow randomly going from right to left
xPosition = 15;
yPosition = random(0, 10);
if (yPosition > 5) {
yConstant = 1;
}
else yConstant = 0;
lcd.setCursor(xPosition, yConstant);
for (int xPosition = 15; xPosition > 1; xPosition--) {
lcd.print("<-");
delay(100);
lcd.clear();
lcd.setCursor((xPosition), yConstant);
}
////////////////////////////
// suppose to print x on the top row and print nothing on buttom row
//and otherwise when button is not pressed print x on bottom and
//print nothing on top row
int rightjump = 0;
rightjump = digitalRead(7);
if (rightjump == 1 ) {
lcd.setCursor(0, 0);
//delay(10);
lcd.print(line2);
//delay(200);
lcd.setCursor(0, 1);
lcd.print(" ");
}
else if ( rightjump == 0 ) {
lcd.setCursor(0, 1);
//delay(10);
lcd.print(line2);
//delay(200);
lcd.setCursor(0, 0);
lcd.print(" ");
}
}