terça-feira, 11 de julho de 2017

jogo no display #1

// Programa caracter animado display lcd i2c;

int brilho = 0;
int tempo = 5;
int estado = 1;
float tencao = 0;
char comando = 'a';
int linha =7;

// PARAMETROS DO LCD ****************************************

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADOR 0x3F // <<
#define BACKLIGHT_PIN 3
#define En 2
#define Rw 1
#define Rs 0
#define D4 4
#define D5 5
#define D6 6
#define D7 7
LiquidCrystal_I2C lcd(I2C_ADOR, En, Rw, Rs, D4, D5, D6, D7);

// **********************************************************






//******************puple gay ***************
byte smiley[8] = {
  B00000,
  B00111,
  B00111,
  B00111,
  B01110,
  B01111,
  B01110,
  B01010,
};

//***************** obstaculo 1*****************
byte smiley1[8] = {
  B00000,
  B00000,
  B00111,
  B00111,
  B00111,
  B01110,
  B01111,
  B01110,
 
};

//***************** obstaculo 2*****************
byte smiley2[8] = {
  B10101,
  B01010,
  B10101,
  B00000,
  B00000,
  B00000,
  B00000,
};
//***************** obstaculo 3*****************
byte smiley3[8] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00100,
  B01110,
  B11111,
};
//***************** obstaculo 4*****************
byte smiley4[8] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B01110,
  B01110,
  B01110,
  B00100
};
//***************** chegada*****************
byte smiley5[8] = {
  B00000,
  B11111,
  B10001,
  B10001,
  B10001,
  B10001,
  B10001,
  B10001,
};

void setup()
{
  Serial.begin(9600);
  lcd.begin (16, 2);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
 
  lcd.createChar(0, smiley);
  lcd.createChar(1, smiley1);
  lcd.createChar(2, smiley2);
  lcd.createChar(3, smiley3);
  lcd.createChar(4, smiley4);
  lcd.createChar(5, smiley5);
}

void loop()
{
  if (Serial.available()) // verifica se existe algo digitado no monitor serial;
  {
    comando = Serial.read(); // carrega o valor digitado no monitor serial na variavel "comando";

    if (comando == '8')
    {
      lcd.clear();
      lcd.setCursor(linha, 0);
      lcd.write(byte(0));
      delay(500);
      lcd.clear();
     
     
    }
     if (comando == '2')
    {
      lcd.clear();
      lcd.setCursor(linha, 1);
      lcd.write(byte(1));
      delay(500);
      lcd.clear();
     
     
    }
     if (comando == '6')
    {
      lcd.clear();
      linha= linha +1;
      lcd.setCursor(linha, 1);
      lcd.write(byte(0));
      delay(500);
     
     
     
    }
    if (comando == '4')
    {
      lcd.clear();
      linha= linha -1;
      lcd.setCursor(linha, 1);
      lcd.write(byte(0));
      delay(500);
     
     
    }
  }
  lcd.setCursor(linha, 1);
  lcd.write(byte(0));
/*
  lcd.setCursor(1, 0);
  lcd.write(byte(1));
  lcd.setCursor(2, 0);
  lcd.write(byte(2));

  lcd.setCursor(0, 1);
  lcd.write(byte(3));
  lcd.setCursor(1, 1);
  lcd.write(byte(4));
  lcd.setCursor(2, 1);
  lcd.write(byte(5));

*/
  //lcd.scrollDisplayLeft();
  //delay(500);
}

Nenhum comentário:

Postar um comentário