LCD Hill Run v2 – Game Runner Interaktif Arduino dengan LCD 16x2 & Buzzer
Komponen dan Perlengkapan
| Arduino Mega 2560 | 1 | ATAU ARDUINO UNO!! Ubah DUCK_PIN dalam kode menjadi 3 dan rerang sesuai jika ingin menggunakan uno |
| Kabel jumper (umum) | 20 | +- 20 diperlukan |
| SparkFun Pushbutton switch 12mm | 2 | |
| Resistor 10k ohm | 2 | |
| Adafruit Standard LCD - 16x2 Putih pada Biru | 1 | |
| Rotary Potentiometer, 10 kohm | 1 | potentiometer lama juga boleh |
| Buzzer | 1 | Buzzer pasif diinginkan, buzzer aktif atau piezo buzzer MUNGKIN bisa bekerja. Tidak diperlukan untuk fungsionalitas, hanya untuk kesenangan. JANGAN BELI PRODUK TERSEBUT! Ini salah; buzzer bukan $225. |
| Breadboard (umum) | 1 | Ukuran penuh direkomendasikan |
Aplikasi dan Layanan Online
| Arduino IDE | Atau web editor jika Anda menggunakan itu. |
Tentang Proyek
Saya hanya seorang anak dan sebagian besar amatir di Arduino. Setelah membaca beberapa proyek project hub dan mempelajari Arduino, saya terinspirasi untuk membuat game menyenangkan ini. Ini tidak membutuhkan terlalu banyak debugging dan sangat keren. Kodenya cukup bersih menurut standar saya. ENJOY!! Harap menghargai dan berkomentar.
Ingatlah untuk mengunduh library yang termasuk dalam program ini dan letakkan di folder direktori. Jika ada kesalahan bahwa tidak dapat menemukan library, maka gunakan sketch>include library. Beri komentar jika ada masalah.
Library di https://github.com/PunkyMunky64/HillRun2Libraries
Kode
Hill Run v2 codeArduino
Kodenya. Ubah DUCK_PIN menjadi 3 jika ingin menggunakan UNO sebagai gantinya. Kodenya cukup kompak dan bersih, menurut saya sendiri.
/* * Copyright (c) 2020 by Miles C. Versi yang ditingkatkan dari hill run dengan interrupt untuk membuat kode lebih baik. PERHATIKAN DUCK_PIN ADALAH 18 BUKAN 4 karena kemampuan interrupt! Hill run, game menyenangkan di mana Anda melompat di atas bukit dan terkurung di bawah gagak. Penyambungan: Arduino +5V ke bus daya breadboard Arduino Ground ke bus ground breadboard Tombol lompat dengan 10k pull down ke ground, dan ke digital pin 2, dan sisi lain ke +5V. Tombol terkurung dengan 10k pull down ke ground, dan ke digital pin 18, dan sisi lain ke +5V. Buzzer pasif dengan satu sisi pada ground dan satu sisi pada digital PWN pin 5. Layar LCD 16x2 16-pin dengan penyambungan arduino normal, seperti dalam pelajaran untuk layar lcd: -K ke ground -A ke +5V -D4 melalui D7 ke pin 9 melalui 12 -E ke pin 8 -RW ke ground -RS ke pin 7 -V0 ke output potentiometer, untuk kecerahan, potentiometer terhubung ke +5V dan ground -VDD ke +5V -VSS ke ground */ #include <LiquidCrystal.h> #include "pitches.h" LiquidCrystal lcd(7, 8, 9, 10, 11, 12); const int JUMP_PIN = 2; const int BUZZER_PIN = 5; const int DUCK_PIN = 18; //change to 3 if you want to use an UNO instead const int JUMP_PITCH = 2700; const int JUMP_PITCH_DURATION = 50; const int DUCK_PITCH = 1350; const int DUCK_PITCH_DURATION = 50; const int DIE_PITCH = 200; const int DIE_PITCH_DURATION = 500; const int TICKSPEED = 90; const int JUMP_LENGTH = 3; const byte stickStep1[8] = { B01110, B01110, B00101, B11111, B10100, B00110, B11001, B00001, }; const byte stickStep2[8] = { B01110, B01110, B00101, B11111, B10100, B00110, B01011, B01000, }; const byte stickJump[8] = { B01110, B01110, B00100, B11111, B00100, B11111, B10001, B00000, }; const byte stickDuck[8] = { B00000, B00000, B00000, B01110, B01110, B11111, B00100, B11111, }; const byte hill[8] = { B00000, B00100, B01010, B01110, B11101, B10101, B11001, B11111, }; const byte crow1[8] = { B00111, B00100, B00110, B01111, B11111, B01111, B00110, B00111, }; const byte crow2[8] { B00111, B00110, B01111, B11111, B01111, B00110, B00110, B00111, }; volatile int jumpPhase = JUMP_LENGTH + 1; int gameTick = 0; int crowX = 40; int hillX = 25; bool playerY = 0; volatile bool ducking = LOW; bool loopBreaker = 1; bool crowGo = 0; int score = 0; void setup() { pinMode(JUMP_PIN, INPUT); pinMode(BUZZER_PIN, OUTPUT); lcd.begin(16, 2); lcd.createChar(0, hill); lcd.createChar(1, stickStep1); lcd.createChar(2, stickStep2); lcd.createChar(3, stickJump); lcd.createChar(4, stickDuck); lcd.createChar(5, crow1); lcd.createChar(6, crow2); attachInterrupt(digitalPinToInterrupt(JUMP_PIN), seeJumping, RISING); attachInterrupt(digitalPinToInterrupt(DUCK_PIN), seeDucking, CHANGE); } void loop() { playerY = 0; if (jumpPhase < JUMP_LENGTH) { playerY = 1; } drawSprites(); loopBreaker = 1; if (hillX < 16) { if (crowX < hillX) { hillX += 8; loopBreaker = 0; } if (loopBreaker) { lcd.setCursor(hillX, 1); lcd.write((byte)0); } } if (hillX < 1) { if (jumpPhase < JUMP_LENGTH) { score++; hillX = 16 + rand() % 8; } else { endGame(); } } if (crowX < 16) { lcd.setCursor(crowX, 0); if (gameTick % 8 < 4) { lcd.write((byte)5); } else { lcd.write((byte)6); } } if (crowX < 1) { if (ducking) { score++; crowX = 24 + rand() % 16; } else { endGame(); } } lcd.setCursor(0, playerY); lcd.print(" "); jumpPhase++; hillX--; crowGo = !crowGo; crowX -= crowGo; gameTick++; delay(TICKSPEED); } void endGame() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Score: "); lcd.setCursor(7, 0); lcd.print(score); tone(BUZZER_PIN, DIE_PITCH, DIE_PITCH_DURATION); while (!digitalRead(JUMP_PIN)) { lcd.setCursor(0, 1); if (millis() % 500 < 250) { lcd.print("Jump to Continue"); } else { lcd.print(" "); } } lcd.clear(); score = 0; hillX = 25; crowX = 40; } void drawSprites() { lcd.setCursor(0, 1 - playerY); if (!ducking) { if (!playerY) { if ((gameTick % 4) < 2 ) { lcd.write((byte)1); } else { lcd.write((byte)2); } } else { lcd.write((byte)3); } } else { lcd.write((byte)4); } lcd.setCursor(1, 1); lcd.print(" "); lcd.setCursor(1, 0); lcd.print(" "); } void seeJumping() { if (jumpPhase > (JUMP_LENGTH + 2) && !ducking) { jumpPhase = 0; tone(BUZZER_PIN, JUMP_PITCH, JUMP_PITCH_DURATION); } } void seeDucking() { ducking = digitalRead(DUCK_PIN); if (ducking) { jumpPhase = JUMP_LENGTH; tone(BUZZER_PIN, DUCK_PITCH, DUCK_PITCH_DURATION); } }
READMEMarkdown
Informasi
"Enjoy this Hillrun game! Jump over hills by pressing jump, and duck under crows by holding duck. DON'T CRASH! If you die, press jump to continue. Score = crows ducked under + hills jumped over GOTO https://create.arduino.cc/projecthub/PunkyMunky64/lcd-hill-run-v2-runner-game-1b0523 for more info. I am only 12 years old and mostly an amateur at Arduino. After reading some project hub projects and learning Arduino, I was inspired to create this fun game. It did not take too much debugging and is really cool. The code is pretty clean by my standards. ENJOY!! Please respect and comment. Remember to download the libraries included in this program and put them in the directory folder. If there is an error that it cannot find the library, then just use sketch>include library. Comment if you have any problems. Libraries at https://github.com/PunkyMunky64/HillRun2Libraries IF YOU WANT TO USE AN UNO INSTEAD: in the code change const int DUCK_PIN to 3. and rewire the duck button from pin 18 to digital pin 3. Copyright (c) HillRun2.ino by Miles C. 2020 under GNU General Public License. For wiring schematic and parts needed, visit the arduino page linked above."
Skematik
Diagram Skematik Rangkaian
hillrun2_zp0SI4wns3.fzz
Ini adalah diagram penyambungan HillRun. JIKA ANDA INGIN MENGGUNAKAN UNO SEBAGAI GANTI: dalam kode ubah const int DUCK_PIN ke 3. dan rerang tombol terkurung dari pin 18 ke digital pin 3.