debanshudas23
Published © GPL3+

LCD Animation and Gaming

Learn how to animate and make games using arduino and lcd

BeginnerFull instructions provided23,106
LCD Animation and Gaming

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic for lcd

Code

code for animation

Arduino
// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

byte arrowhead[]={
  B00001,
  B00011,
  B00111,
  B01111,
  B00111,
  B00011,
  B00001,
  B00000
};

byte arrowbody[]={
  B00000,
  B00000,
  B00000,
  B11111,
  B11111,
  B00000,
  B00000,
  B00000
};

byte arrowtail[]={
  B00011,
  B00111,
  B11111,
  B11111,
  B11111,
  B00111,
  B00011,
  B00000
};

byte man[] = {
  B01110,
  B01110,
  B00100,
  B01110,
  B10101,
  B00100,
  B01010,
  B10001
};

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.createChar(0,arrowhead);
  lcd.createChar(1,arrowbody);
  lcd.createChar(2,arrowtail);
  lcd.createChar(3,man);
  lcd.begin(16, 2);
  // Print a message to the LCD.
  //lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  //lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  //lcd.print(millis() / 1000);
  int n;
  n=15;
  while(n!=-1){
    lcd.clear();
    delay(10);
    lcd.setCursor(0,0);
    lcd.print("by Debanshu Das");
   /* lcd.setCursor(1,1);
    lcd.write(byte(3));
    lcd.setCursor(n,1);
    lcd.write(byte(0));
    lcd.write(byte(1));
    lcd.write(byte(2));*/
    delay(65);
    n--;
  }
}

code for game

Arduino
// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int level=1;
int score=0;

byte arrowhead[]={
  B00001,
  B00011,
  B00111,
  B01111,
  B00111,
  B00011,
  B00001,
  B00000
};

byte arrowbody[]={
  B00000,
  B00000,
  B00000,
  B11111,
  B11111,
  B00000,
  B00000,
  B00000
};

byte arrowtail[]={
  B00011,
  B00111,
  B11111,
  B11111,
  B11111,
  B00111,
  B00011,
  B00000
};

byte man[] = {
  B01110,
  B01110,
  B00100,
  B01110,
  B10101,
  B00100,
  B01010,
  B10001
};

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.createChar(0,arrowhead);
  lcd.createChar(1,arrowbody);
  lcd.createChar(2,arrowtail);
  lcd.createChar(3,man);
  lcd.begin(16, 2);
  attachInterrupt(0,buttonin,CHANGE);
  randomSeed(analogRead(A0));
  // Print a message to the LCD.
  //lcd.print("hello, world!");
}

  int n;
void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  //lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  //lcd.print(millis() / 1000);
  n=15;
  int rnd;
  rnd=random(15,25);
  while(n!=-1){
    lcd.clear();
    delay(10);
    drawman();
    lcd.setCursor(n,1);
    if(n==1){
      if(level==1){
        stopgame();
        continue;
      }
    }
    lcd.write(byte(0));
    lcd.write(byte(1));
    lcd.write(byte(2));
    lcd.setCursor(10,0);
    lcd.print(score);
    delay(100-rnd);
    n--;
    score++;
    if(level==0)
      score--;
  }
}

void drawman(){
    lcd.setCursor(1,level);
    lcd.write(byte(3));
}

void buttonin(){
  if(digitalRead(2)==LOW){
    level=0;
  }
  else{
    level=1;
  }
}


void stopgame(){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Game over");
  lcd.setCursor(10,0);
  lcd.print(score);
  level=1;
  score=0;
  n=15;
  delay(3000);
  return;
}

Credits

debanshudas23
0 projects • 11 followers
Contact

Comments

Please log in or sign up to comment.