Components and supplies
Alphanumeric LCD, 16 x 2
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
code for game
arduino
1 2 3// include the library code: 4#include <LiquidCrystal.h> 5 6// initialize the library by associating any needed LCD interface pin 7// with the arduino pin number it is connected to 8const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7; 9LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 10int level=1; 11int score=0; 12 13byte arrowhead[]={ 14 B00001, 15 B00011, 16 B00111, 17 B01111, 18 B00111, 19 B00011, 20 B00001, 21 B00000 22}; 23 24byte arrowbody[]={ 25 B00000, 26 B00000, 27 B00000, 28 B11111, 29 B11111, 30 B00000, 31 B00000, 32 B00000 33}; 34 35byte arrowtail[]={ 36 B00011, 37 B00111, 38 B11111, 39 B11111, 40 B11111, 41 B00111, 42 B00011, 43 B00000 44}; 45 46byte man[] = { 47 B01110, 48 B01110, 49 B00100, 50 B01110, 51 B10101, 52 B00100, 53 B01010, 54 B10001 55}; 56 57void setup() { 58 // set up the LCD's number of columns and rows: 59 lcd.createChar(0,arrowhead); 60 lcd.createChar(1,arrowbody); 61 lcd.createChar(2,arrowtail); 62 lcd.createChar(3,man); 63 lcd.begin(16, 2); 64 attachInterrupt(0,buttonin,CHANGE); 65 randomSeed(analogRead(A0)); 66 // Print a message to the LCD. 67 //lcd.print("hello, world!"); 68} 69 70 int n; 71void loop() { 72 // set the cursor to column 0, line 1 73 // (note: line 1 is the second row, since counting begins with 0): 74 //lcd.setCursor(0, 1); 75 // print the number of seconds since reset: 76 //lcd.print(millis() / 1000); 77 n=15; 78 int rnd; 79 rnd=random(15,25); 80 while(n!=-1){ 81 lcd.clear(); 82 delay(10); 83 drawman(); 84 lcd.setCursor(n,1); 85 if(n==1){ 86 if(level==1){ 87 stopgame(); 88 continue; 89 } 90 } 91 lcd.write(byte(0)); 92 lcd.write(byte(1)); 93 lcd.write(byte(2)); 94 lcd.setCursor(10,0); 95 lcd.print(score); 96 delay(100-rnd); 97 n--; 98 score++; 99 if(level==0) 100 score--; 101 } 102} 103 104void drawman(){ 105 lcd.setCursor(1,level); 106 lcd.write(byte(3)); 107} 108 109void buttonin(){ 110 if(digitalRead(2)==LOW){ 111 level=0; 112 } 113 else{ 114 level=1; 115 } 116} 117 118 119void stopgame(){ 120 lcd.clear(); 121 lcd.setCursor(0,0); 122 lcd.print("Game over"); 123 lcd.setCursor(10,0); 124 lcd.print(score); 125 level=1; 126 score=0; 127 n=15; 128 delay(3000); 129 return; 130} 131
code for animation
arduino
1 2// include the library code: 3#include <LiquidCrystal.h> 4 5// initialize the library by associating any needed LCD interface pin 6// with the arduino pin number it is connected to 7const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7; 8LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 9 10byte arrowhead[]={ 11 B00001, 12 B00011, 13 B00111, 14 B01111, 15 B00111, 16 B00011, 17 B00001, 18 B00000 19}; 20 21byte arrowbody[]={ 22 B00000, 23 B00000, 24 B00000, 25 B11111, 26 B11111, 27 B00000, 28 B00000, 29 B00000 30}; 31 32byte arrowtail[]={ 33 B00011, 34 B00111, 35 B11111, 36 B11111, 37 B11111, 38 B00111, 39 B00011, 40 B00000 41}; 42 43byte man[] = { 44 B01110, 45 B01110, 46 B00100, 47 B01110, 48 B10101, 49 B00100, 50 B01010, 51 B10001 52}; 53 54void setup() { 55 // set up the LCD's number of columns and rows: 56 lcd.createChar(0,arrowhead); 57 lcd.createChar(1,arrowbody); 58 lcd.createChar(2,arrowtail); 59 lcd.createChar(3,man); 60 lcd.begin(16, 2); 61 // Print a message to the LCD. 62 //lcd.print("hello, world!"); 63} 64 65void loop() { 66 // set the cursor to column 0, line 1 67 // (note: line 1 is the second row, since counting begins with 0): 68 //lcd.setCursor(0, 1); 69 // print the number of seconds since reset: 70 //lcd.print(millis() / 1000); 71 int n; 72 n=15; 73 while(n!=-1){ 74 lcd.clear(); 75 delay(10); 76 lcd.setCursor(0,0); 77 lcd.print("by Debanshu Das"); 78 /* lcd.setCursor(1,1); 79 lcd.write(byte(3)); 80 lcd.setCursor(n,1); 81 lcd.write(byte(0)); 82 lcd.write(byte(1)); 83 lcd.write(byte(2));*/ 84 delay(65); 85 n--; 86 } 87}
code for animation
arduino
1 2// include the library code: 3#include <LiquidCrystal.h> 4 5// initialize the library by associating any needed LCD interface pin 6// with the arduino pin number it is connected to 7const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7; 8LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 9 10byte arrowhead[]={ 11 B00001, 12 B00011, 13 B00111, 14 B01111, 15 B00111, 16 B00011, 17 B00001, 18 B00000 19}; 20 21byte arrowbody[]={ 22 B00000, 23 B00000, 24 B00000, 25 B11111, 26 B11111, 27 B00000, 28 B00000, 29 B00000 30}; 31 32byte arrowtail[]={ 33 B00011, 34 B00111, 35 B11111, 36 B11111, 37 B11111, 38 B00111, 39 B00011, 40 B00000 41}; 42 43byte man[] = { 44 B01110, 45 B01110, 46 B00100, 47 B01110, 48 B10101, 49 B00100, 50 B01010, 51 B10001 52}; 53 54void setup() { 55 // set up the LCD's number of columns and rows: 56 lcd.createChar(0,arrowhead); 57 lcd.createChar(1,arrowbody); 58 lcd.createChar(2,arrowtail); 59 lcd.createChar(3,man); 60 lcd.begin(16, 2); 61 // Print a message to the LCD. 62 //lcd.print("hello, world!"); 63} 64 65void loop() { 66 // set the cursor to column 0, line 1 67 // (note: line 1 is the second row, since counting begins with 0): 68 //lcd.setCursor(0, 1); 69 // print the number of seconds since reset: 70 //lcd.print(millis() / 1000); 71 int n; 72 n=15; 73 while(n!=-1){ 74 lcd.clear(); 75 delay(10); 76 lcd.setCursor(0,0); 77 lcd.print("by Debanshu Das"); 78 /* lcd.setCursor(1,1); 79 lcd.write(byte(3)); 80 lcd.setCursor(n,1); 81 lcd.write(byte(0)); 82 lcd.write(byte(1)); 83 lcd.write(byte(2));*/ 84 delay(65); 85 n--; 86 } 87}
Downloadable files
Schematic for lcd
Schematic for lcd
Schematic for lcd
Schematic for lcd
Comments
Only logged in users can leave comments