กลับไปหน้ารวมไฟล์
lcd-game-console-38bc81.md

สวัสดีครับ นี่เป็นโปรเจกต์ที่ง่ายมาก จึงไม่จำเป็นต้องมีคำอธิบายเพิ่มเติม เพียงแค่เตรียมชิ้นส่วนและคัดลอกโค้ดพร้อมกับแผนภาพการต่อสาย!

วิธีการเล่น!

PITF-ARD
คลิกเพื่อเริ่มเกม เดินไปทางขวาเพื่อหากุญแจประตูเพื่อผ่านด่าน เลื่อน joystick ขึ้นเพื่อกระโดด

#include 
#include
#include
LiquidCrystal_I2C lcd(0x27,16,2);
// การประกาศตัวแปร
int game = 0;
int gameover = 0;
int le = 0;
float ll = 0;
int key = LOW;
int mov=0;
int cc=1;
int screen1[202];
int screen2[202];
int ind = 0;
int randomNumber=0;
int ax=0;
int ay=0;
int timegame=2000;
int clef = 0;
int jump = 0;
int path = 42;
int ck = 2;
// การประกาศตัวอักษร
byte man1[] = {0x04, 0x0E, 0x0E, 0x0E, 0x04, 0x04, 0x1F, 0x1F} ;
byte man2[] = {0x04, 0x1E, 0x05, 0x04, 0x0B, 0x10, 0x1F, 0x1F} ;
byte man3[] = {0x04, 0x0F, 0x14, 0x04, 0x1A, 0x01, 0x1F, 0x1F} ;
byte man4[] = {0x15, 0x0E, 0x04, 0x0E, 0x11, 0x00, 0x00, 0x00} ;
byte man5[] = {0x15, 0x0E, 0x04, 0x0E, 0x11, 0x00, 0x1F, 0x1F} ;
byte man6[] = {0x00, 0x00, 0x04, 0x0E, 0x04, 0x04, 0x1F, 0x1F} ;
byte flat[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F};
byte hole[] = {0x0E, 0x1F, 0x15, 0x1B, 0x0E, 0x04, 0x1F, 0x1F} ;
byte m1[] = {0x1F, 0x1F, 0x1F, 0x19, 0x10, 0x00, 0x00, 0x00} ;
byte m2[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0F, 0x06, 0x00} ;
byte m3[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0C, 0x00, 0x00} ;
byte m4[] = {0x1F, 0x1F, 0x00, 0x0A, 0x00, 0x0A, 0x00, 0x0A} ;
byte m5[] = {0x1F, 0x1F, 0x1F, 0x00, 0x0A, 0x00, 0x0A, 0x00} ;
byte m6[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x0A, 0x00} ;
byte keys[8] = {0x00, 0x03, 0x1F, 0x13, 0x00, 0x00, 0x1F, 0x1F} ;
byte dooro[8] = {0x1F, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x1F} ;
byte door[8] = {0x1F, 0x1F, 0x1D, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F} ;
void setup(){
lcd.init();
lcd.backlight();
lcd.home();
lcd.clear();
// การเชื่อมโยงตัวอักษร
lcd.createChar(1, man1);
lcd.createChar(2, flat);
lcd.createChar(3, hole);
lcd.createChar(8, keys);
lcd.createChar(7, door);
}
void loop(){
if (game == 0)
{
if (gameover == 0)
{
// หน้าจอไตเติ้ล
lcd.home();
lcd.setCursor(0, 0);
lcd.print(" Key game");
lcd.setCursor(0, 1);
lcd.print(" 2020");
key = digitalRead(7);
if (key == LOW)
{
// เริ่มต้นเกม
lcd.clear();
lcd.home();
le = 0;
ll = 0;
gameover = 1;
cc=2;
jump = 0;
path = 16;
}
}
else
{
// หน้าจอใหม่ - เริ่มต้น
randomSeed(analogRead(0));
game = 1;
key = LOW;
le = le + 1;
ll = ll + 1;
path = path + 10;
if (path>202)
{
path = 202;
}
ind = 0;
for(int s=0;s<(path + 10);s++)
{
screen1[s] = 2;
}
for(int s=11;s<(path -2 );s=s+3)
{
randomNumber = int(random(2, 4));
//randomNumber = 3;
screen1[s] = randomNumber;
}
screen1[6]=7;
screen1[path + 1]=8;
for(int s=0;s<(path+10);s++)
{
randomNumber = int(random(4, 7));
screen2[s] = randomNumber;
}
if ((ll/2) == int(ll/2))
{
lcd.createChar(4, m4);
lcd.createChar(5, m5);
lcd.createChar(6, m6);
}
else
{
lcd.createChar(4, m1);
lcd.createChar(5, m2);
lcd.createChar(6, m3);
}
timegame = 2000;
clef = 0;
lcd.createChar(7, door);
cc = 2;
ck = 2;
}
}
else
{
// ลูปเกม
if (jump == 3)
{
jump = 0;
}
lcd.home();
timegame = timegame - le;
for(int s=ind;s<(ind+16);s++)
{
lcd.setCursor(s-ind, 0);
lcd.write(byte(screen2[s]));
lcd.setCursor(s-ind, 1);
lcd.write(byte(screen1[s]));
}
if (timegame < 0)
{
timegame = 0;
}
lcd.setCursor(16-String(timegame).length(), 0);
lcd.print(timegame);
if (jump == 0)
{
lcd.setCursor(7, 1);
lcd.write(byte(1));
ck = screen1[ind+7];
if (mov == 1)
{
if (cc==1)
{
lcd.createChar(1, man1);
}
else
{
lcd.createChar(1, man1);
}
mov = 0;
}
else
{
lcd.createChar(1, man1);
mov = 1;
}
}
if (jump > 0)
{
lcd.setCursor(7, 0);
lcd.write(byte(1));
lcd.createChar(1, man4);
if (cc == 2)
{
ind = ind + 1;
}
else
{
ind = ind - 1;
}
if (jump == 1)
{
jump = 2;

ข้อมูล Frontmatter ดั้งเดิม

title: "Lcd game console"
description: "A console made from an lcd and a joystick"
author: "vovxb"
category: ""
tags:
  - "lcd"
views: 2590
likes: 0
price: 1120
difficulty: "Easy"
components:
  - "1x I2C 16x2 Arduino LCD Display Module"
  - "1x Arduino UNO"
  - "1x Analog joystick (Generic)"
  - "1x Solderless Breadboard Full Size"
  - "1x USB-A to Mini-USB Cable"
tools: []
apps:
  - "1x Arduino Web Editor"
  - "1x Arduino IDE"
downloadableFiles:
  - "https://projects.arduinocontent.cc/5ca0e162-e4bd-457e-a462-5a98598932fa.ino"
documentationLinks: []
passwordHash: "0ffa32dc41d1cc259188c385ae03db44288179ee90d6219e0a2c98ca55702791"
encryptedPayload: "U2FsdGVkX19DF3NpAg3iwbTVn4jpwY8zLRGPuJNEmKMfOezhE64uUsHP9ueItDe8oKYxjcv4OKWsuo/Xw/Wtf1DLS1U1rfjccivjvwiI3ROCPUJRaVKXknl+QRVSY9+p"
seoDescription: "Create your own Lcd game console using an lcd and joystick. A simple DIY Arduino project for gamers."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/lcd-game-console-38bc81_cover.jpg"
lang: "th"