I wrote this code and it works but the pixel gets really dim when it is moving so fast is there a way to fix this.
#include <SoftwareSerial.h>
#include <serLCD.h>
#include "Game.h"
const int buttonPin = 3;
int buttonState;
int increment = + 1;
int increment1 = + 1;
int x = 1, c = 1;
int pin = 2;
int time = 50;
serLCD lcd(pin);
int num = 1;
byte dot1[8] = {
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11110000
};
byte dot2[8] = {
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11101000
};
byte dot3[8] = {
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100100
};
byte dot4[8] = {
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100010
};
byte dot5[8] = {
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100001
};
byte arrow[8] = {
B11100000,
B11100100,
B11101110,
B11110101,
B11100100,
B11100100,
B11100100,
B11100100
};
void arrow1() {
lcd.setCursor(2, 8);
lcd.printCustomChar(7);
};
void setup() {
{
lcd.setBrightness(30);
Serial.begin(9600);
lcd.createChar(1, dot1);
lcd.createChar(2, dot2);
lcd.createChar(3, dot3);
lcd.createChar(4, dot4);
lcd.createChar(5, dot5);
lcd.createChar(7, arrow);
pinMode(buttonPin, INPUT);
lcd.clear();
arrow1();
}
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.setCursor(1, x);
lcd.printCustomChar(c);
delay(time);
c = c + increment1;
if (c < 2)increment1 = +1;
if (c > 5) {
c = 1;
lcd.clear();
arrow1();
x = x + increment;
if (x < 2)increment = +1;
if (x > 15) {
increment = -1;
}
Serial.println(c);
}
}
else {
if (c == 3 && x == 8) {
arrow1();
lcd.setCursor(1, 1);
lcd.write(" Winner ");
delay(1000);
}
}
}