Can you help me to fix this code. The problem is that it doesn't receive the commands. It is a game of an arrow dodging random obstacles.
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
// Pulsadores
int UP = 11;
int DOWN = 12;
int score;
String flech= "->";
int posiflech;
signed char pos1;
signed char pos2;
int a;
// Definición de los mensajes a mostrar en el LCD
const char* mensaje1 = "Homework Number 5. Student: Hamira Huaccho";
const char* mensaje2 = "Pulse any button";
void setup()
{
Serial.begin(9600);
pinMode(UP, INPUT);
pinMode(DOWN, INPUT);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(mensaje1);
lcd.setCursor(0, 1);
lcd.print(mensaje2);
}
void displayTextSequence() {
// Mostrar el mensaje en movimiento en la primera fila
for (int i = 0; i < strlen(mensaje1) + 16; i++) {
lcd.clear();
// Imprimir el mensaje en movimiento en la primera fila
lcd.setCursor(0, 0);
if (i < strlen(mensaje1))
lcd.print(mensaje1 + i);
else
lcd.print(mensaje1);
// Imprimir el mensaje estático en la segunda fila
lcd.setCursor(0, 1);
lcd.print(mensaje2);
delay(250);
}
}
void loop(){
if (digitalRead(UP) == 0 || digitalRead(DOWN) == 0){
lcd.clear();
pos1= random(3,16);
pos2= random(3,16);
while (abs(pos1 - pos2) <= 2){
pos1 = random(3, 16);
pos2 = random(3, 16);}
lcd.setCursor(pos1, 0);
lcd.print("|");
lcd.setCursor(pos2, 1);
lcd.print("|");
for (int lug=0; lug<16; lug++){
delay(800);
lcd.setCursor(lug,a);
lcd.print("->");
lcd.setCursor(lug-1,a);
lcd.print(" ");
if(digitalRead(DOWN) == 0 || digitalRead(UP)== 0){ //Condicional para el pulsador DOWN
lcd.setCursor(lug-1,a);
lcd.print(" ");
if(digitalRead(UP) == 0){
a=0;}
if(digitalRead(DOWN) == 0){
a=1;}
}
if(a==0 && lug == pos1 + 1 || a==1 && lug == pos2 + 1){
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("You lose!");
delay(800);
resetJug();
break;}
if (lug==15){
lcd.clear();
lcd.setCursor(1, 0);
score++;
lcd.print("Score:");
lcd.setCursor(7, 0);
lcd.print(score);}
}
}
}
void resetJug(){
score= 0;
}