กลับไปหน้ารวมไฟล์
ledstrike-game-with-arduino-plug-and-make-kit-4bf8f2.md

เกม LedStrike ด้วย Arduino Plug and Make Kit

ตลอด 15 ปีที่ผ่านมา การสร้างโปรเจกต์ Arduino มักจะต้องเจอสาย Jumper ที่พันกันยุ่งเหยิงบน Breadboard สีขาว แต่ เกม LedStrike นี้แสดงให้เห็นถึงการเปลี่ยนแปลงครั้งใหญ่ในสถาปัตยกรรมของ Arduino ด้วย Plug and Make Kit (Modulino) โดยใช้สาย Qwiic I2C ที่สามารถเชื่อมต่อเข้าด้วยกันได้อย่างง่ายดาย ทำให้สามารถมุ่งเน้นไปที่ Logic ของเกมที่เขียนด้วย C++ ระดับสูงได้อย่างเต็มที่ แทนที่จะต้องเสียเวลาในการ Debug สายไฟที่หลวม

1306_oled_retro_game_display_1772681532057.png

โปรโตคอล Qwiic Daisy-Chain

ฮาร์ดแวร์ดูเหมือนผลิตภัณฑ์เชิงพาณิชย์ทันที

  1. เริ่มต้นด้วย Arduino UNO R4 WiFi
  2. เสียบสาย I2C ขนาดเล็กแบบ 4-pin จากบอร์ดเข้ากับ Modulino Pixels (แผง RGB LED)
  3. จาก Pixels ให้เสียบสายอีกเส้นตรงไปยัง Modulino Buzzer
  4. จากนั้นไปยัง Modulino Buttons
  5. ไม่มีสายไฟเลี้ยง, ไม่มีสาย GND, ไม่มี Resistor โดย I2C data bus จะจัดการการเชื่อมต่อที่ถูกต้องผ่าน Hexadecimal Address อย่างอัตโนมัติ!

การพัฒนา "Strike" State Machine

เกมนี้เรียบง่าย: พิกเซลจะเด้งไปมาซ้ายขวาบน Modulino Pixel Array กดปุ่มเมื่อพิกเซลอยู่ตรงกลางพอดี!

  • เนื่องจากฮาร์ดแวร์อาศัย Modulino Library เฉพาะ ทำให้โค้ดมีความซับซ้อนน้อยลงอย่างมาก
#include <ModulinoPixels.h>
#include <ModulinoButtons.h>

ModulinoPixels pixels;
ModulinoButtons buttons;

void checkStrike() {
  if (buttons.isPressed(0) && currentPixel == 4) { // Hit dead center!
    pixels.setAllSpace(0, 255, 0); // Flash Green!
    gameSpeed -= 15; // Make the next level insanely fast!
  } else {
    // Player missed!
  }
}
  • ด้วยการตัดการ Debouncing ของ millis() ที่ซับซ้อน และ Data Line ของ FastLED ออกไป นักพัฒนาจึงสามารถมุ่งเน้น 100% ไปที่โครงสร้างของ Game Loop ได้อย่างสมบูรณ์!

ระบบนิเวศของ Modulino Parts

  • Arduino UNO R4 WiFi (ต้องใช้สถาปัตยกรรมที่ทันสมัย)
  • Arduino Plug and Make Kit โดยเฉพาะการใช้:
    • Modulino Pixels (ตัวแสดงผลภาพ)
    • Modulino Buttons (อินพุตแบบสัมผัส)
    • Modulino Buzzer (เสียงเตือน Game Over)
  • สายเชื่อมต่อ Qwiic / Stemma QT I2C (กลไกการเชื่อมต่อที่มหัศจรรย์!)

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

title: "LedStrike Game with Arduino Plug and Make Kit"
description: "Modular prototyping! Bypass messy breadboards entirely using the brand new Modulino ecosystem on the UNO R4 WiFi to construct an incredibly clean, tactile, sound-emitting reflex game."
category: "Gaming & Entertainment"
difficulty: "Easy"