hey im making this Arduino pong project and for some reason the lcd is only displaying squares on the top row ive switched pins and moved wires around and nothing still here is the wiring diagram and code
code
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
byte customchar2[8] = { B00100, B01110, B11111, B11111, B01110, B00100, B00000};
byte customchar1[8] = { B00000, B00100, B01110, B11111, B11111, B01110, B00100};
int i = 0;
int a = 1;
int play = 0;
int ispeed = 150;
void setup()
{
lcd.begin(16, 2);
lcd.clear();
lcd.createChar(1, customchar1);
lcd.createChar(2, customchar2);
pinMode(8, INPUT);
digitalWrite(8, HIGH);
pinMode(9, INPUT);
digitalWrite(9, HIGH);
pinMode(10, INPUT);
digitalWrite(10, HIGH);
pinMode(11, INPUT);
digitalWrite(11, HIGH);
Serial.begin(9600);
}
void loop()
{
if(play == 0)
{
ispeed = 150;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("press any button");
lcd.setCursor(2,1);
lcd.print("to start....");
delay(250);
Serial.println(play);
if(digitalRead(8) == LOW || digitalRead(9) == LOW || digitalRead(10) == LOW || digitalRead(11) == LOW )
{
play = 1;
lcd.clear();
}
}
if(play == 1)
{
Serial.println(ispeed);
delay(ispeed);
lcd.clear();
lcd.setCursor(i,0);
lcd.write(1);
if((digitalRead(8) == LOW || digitalRead(9) == LOW )&& i > 2)
{
a = 4;
i = -1;
}
if((digitalRead(10) == LOW || digitalRead(11) == LOW )&& i < 13)
{
a = 3;
i = 16;
}
//traveling toward right
if(a == 1)
{
i++;
if(i > 13 && digitalRead(10) == LOW)
{
a = 2;
}
else if(i < 2 && digitalRead(9) == LOW)
{
a = 1;
}
else if(i > 14 && digitalRead(11) == LOW)
{
if(ispeed > 20)
{
ispeed = ispeed - 10;
}
a = 2;
}
else if(i < 1 && digitalRead(8) == LOW)
{
if(ispeed > 20)
{
ispeed = ispeed - 10;
}
a = 1;
}
else if(i == -1 && a == 2)
{
a = 4;
}
else if(i == 16 && a == 1)
{
a = 3;
}
}
//traveling toward left
else if(a == 2)
{
i--;
//<--
// Serial.println("2");
if(i > 13 && digitalRead(10) == LOW)
{
a = 2;
}
else if(i < 2 && digitalRead(9) == LOW)
{
a = 1;
}
else if(i > 14 && digitalRead(11) == LOW)
{
if(ispeed > 0)
{
ispeed = ispeed - 10;
}
a = 2;
}
else if(i < 1 && digitalRead(8) == LOW)
{
if(ispeed > 0)
{
ispeed = ispeed - 10;
}
a = 1;
}
else if(i == -1 && a == 2)
{
a = 4;
}
else if(i == 16 && a == 1)
{
a = 3;
}
}
//right side looses
else if(a == 3)
{
lcd.setCursor(4,0);
lcd.print("LOSER!!!");
lcd.setCursor(13,1);
lcd.print("-->");
delay(4000);
play = 0;
a = 2;
}
//left side looses
else if(a == 4)
{
lcd.setCursor(4,0);
lcd.print("LOSER!!!");
lcd.setCursor(0,1);
lcd.print("<--");
delay(4000);
play = 0;
a = 1;
}
}
}
another thing i want to add is that i can kinda see blocks at the bottom but when i try to adjust it using the potiemter it doesent do anything