//https://www.arduino.cc/reference/en/libraries/liquidcrystal/
#include <LiquidCrystal.h> //biblioteca LiquidCrystal
//Pinos do Display
const int rs = 8;
const int en = 9;
const int d4 = 4;
const int d5 = 5;
const int d6 = 6;
const int d7 = 7;
//botão
int Botao1 = 2;
int estado1;
//pista com carros
int carU[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0};
int carD[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0};
int nrCarU;
bool die = false;
//símbolo do carro
byte carChar[8] = {
0b11011,
0b11011,
0b00000,
0b01110,
0b01110,
0b00000,
0b11011,
0b11011
};//from https://omerk.github.io/lcdchargen/
//dino
byte dinoChar[8] = {
0b00110,
0b00111,
0b01110,
0b01111,
0b01111,
0b11110,
0b01110,
0b01010
};
//Cactus
byte cactusChar[8] = {
0b10101,
0b10101,
0b11111,
0b01110,
0b01110,
0b00100,
0b00100,
0b00100
};
//Meteor
byte meteorChar[8] = {
0b00010,
0b00101,
0b11010,
0b11100,
0b11100,
0b11100,
0b01000,
0b00000
};
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int i = 0;
void setup()
{
lcd.createChar(0, dinoChar);// novo caracter pos 0- from: https://omerk.github.io/lcdchargen/
lcd.createChar(1, cactusChar);
lcd.createChar(2, meteorChar);
lcd.begin(16, 2);// LCD - 16 colunas por 2 linhas
Serial.begin(9600);
pinMode(Botao1, INPUT);
nrCarU = sizeof(carU);
}
void escreva (char txtA[], char txtB[])
{
lcd.setCursor(0, 0);
lcd.print(txtA);
lcd.setCursor(0, 1);// coluna 2 e linha 1
lcd.print(txtB);
}
void inCar(int col, int lin) {
lcd.setCursor(col, lin);
lcd.write((uint8_t)1);
}
void outCar(int col, int lin) {
lcd.setCursor(col, lin);
lcd.print(" ");
}
void renderCol(int posCar , int col) {
bt();
if (carU[posCar] == 1 and col == 1 and estado1 == HIGH)
{
escreva("Acidente.... ", "Continuando ");
delay(2000);
die = true;
}
if (carD[posCar] == 1 and col == 1 and estado1 == LOW)
{
lcd.clear();
escreva("Acidente....", "Continuando...");
delay(2000);
die = true;
}
if (die == false)
{
if (carU[posCar] == 1) {
inCar(col, 0);
}
else
{
outCar(col, 0);
}
if (carD[posCar] == 1) {
inCar(col, 1);
}
else
{
outCar(col, 1);
}
}
if (die ==true)
{
lcd.clear();
die=false;
}
}
void render() {
for (int i = 0 ; i < 48 ; i++) {
bt();
renderCol(15 + i, 15);
renderCol(14 + i, 14);
renderCol(13 + i, 13);
renderCol(12 + i, 12);
renderCol(11 + i, 11);
renderCol(10 + i, 10);
renderCol(9 + i, 9);
renderCol(8 + i, 8);
renderCol(7 + i, 7);
renderCol(6 + i, 6);
renderCol(5 + i, 5);
renderCol(4 + i, 4);
renderCol(3 + i, 3);
renderCol(2 + i, 2);
renderCol(1 + i, 1);
renderCol(0 + i, 0);
delay(300);
if (i==47){
escreva(" VENCEDOR!!!", " :)");
delay(2000);
}
}
}
void bt()
{
estado1 = digitalRead(Botao1);
if (estado1 == HIGH)
{
lcd.setCursor(1, 0);
lcd.write((uint8_t)0);
}
else
{
lcd.setCursor(1, 1);
lcd.write((uint8_t)0);
}
}
void loop()
{
escreva("SEJA BEM-VINDO!!!"," CC - UFFS");
delay(1000);
render();
delay(2000);
}