#include <LCD_I2C.h>
LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change according
byte customChar1[] = {
B00000,
B00000,
B00000,
B00011,
B01111,
B11111,
B11111,
B10100
};
byte customChar2[] = {
B00000,
B00000,
B00000,
B00000,
B11010,
B11100,
B11100,
B10100
};
void setup()
{
pinMode(7,INPUT_PULLUP);
lcd.begin(); // If you are using more I2C devices using the Wire library use lcd.begin(false)
// this stop the library(LCD_I2C) from calling Wire.begin()
lcd.backlight();
lcd.createChar(1, customChar2);
lcd.createChar(0, customChar1);
}
int cactus1x = 17;
int cactus1y = 0;
int cactus2x = 17;
int cactus2y = 0;
int spawnindelay = 7;
bool die;
int points;
void loop()
{
int randomizer;
int value;
value=digitalRead(7);
randomSeed(analogRead(0));
if(die==true) {
delay(1000);
die=false;
cactus1x = 17;
cactus1y = 0;
cactus2x = 17;
cactus2y = 0;
spawnindelay = 7;
points=0;
}
lcd.clear();
if (cactus1x < 17) {
cactus1x--;
if (cactus1x == -1 ) {
points++;
cactus1x=17;
if (points ==5) {
lcd.setCursor(0,0);
lcd.print("CONGRATULATION");
delay(1000);
lcd.setCursor(0,1);
lcd.print("NO EXTINCTION!");
delay(2500);
die = true;
return;
}
}
else {
lcd.setCursor(cactus1x,cactus1y);
lcd.print('/');
}
if (cactus1x ==1) {
if (cactus1y ==0 && value == LOW) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Game ");
delay(400);
lcd.print("Over: ");
delay(400);
lcd.print(points);
die=true;
return;
}
if (cactus1y ==1 && value == HIGH) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Game ");
delay(400);
lcd.print("Over: ");
delay(400);
lcd.print(points);
die=true;
return;
}
}
}
if (cactus2x < 17) {
cactus2x--;
if (cactus2x == -1 ) {
points++;
cactus2x=17;
}
else {
lcd.setCursor(cactus2x,cactus2y);
lcd.print('/');
}
if (cactus2x ==1) {
if (cactus2y ==0 && value == LOW) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Game ");
delay(400);
lcd.print("Over: ");
delay(400);
lcd.print(points);
die=true;
return;
}
if (cactus2y ==1 && value == HIGH) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Game ");
delay(400);
lcd.print("Over: ");
delay(400);
lcd.print(points);
die=true;
return;
}
}
}
if (value == HIGH){
value=digitalRead(7);
value=digitalRead(8);
lcd.setCursor(1,1);
lcd.write(0);
lcd.write(1);
value=digitalRead(7);
}
else if (value == LOW){
value=digitalRead(7);
lcd.setCursor(1,0);
lcd.write(0);
lcd.write(1);
value=digitalRead(7);
}
if (spawnindelay ==0) {
if (cactus1x ==17){
cactus1x = 16;
int randomCactus1y = random (0,2);
cactus1y = randomCactus1y;
lcd.setCursor(cactus1x,randomCactus1y);
lcd.print('/');
}
else if (cactus2x ==17) {
cactus2x = 16;
int randomCactus2y = random (0,2);
cactus2y = randomCactus2y;
lcd.setCursor(cactus2x,randomCactus2y);
lcd.print('/');
}
int randomspacegap = random (5,10);
spawnindelay=randomspacegap;
} else {
spawnindelay--;
}
delay(50);
}