Cov txheej txheem:

POiNG! - Arduino Arcade Game!: 3 Kauj Ruam
POiNG! - Arduino Arcade Game!: 3 Kauj Ruam

Video: POiNG! - Arduino Arcade Game!: 3 Kauj Ruam

Video: POiNG! - Arduino Arcade Game!: 3 Kauj Ruam
Video: Amazing arduino project 2024, Kaum ib hlis
Anonim
Image
Image
POiNG! - Arduino Arcade Game!
POiNG! - Arduino Arcade Game!

Peb yuav tsim lub PONG-style arcade game uas siv cov khoom los ntawm "Cov Khoom Siv Ua tiav tshaj plaws UNO R3 Project" cov khoom siv los ntawm Elegoo Inc.

Kev Qhia Tawm Tag Nrho - Feem ntau ntawm ntu uas muab rau Cov Lus Qhia no tau muab rau tus sau los ntawm Elegoo Inc.

Kuv tau xav tsim ib qhov haujlwm siv LED Matrix module. Qhov yooj yim 8x8 LED zaub yuav tsum tau siv cov ntawv hloov pauv ntxiv kom muaj peev xwm hais qhia tus kheej LEDs hauv daim ntawv. Hloov chaw, txoj haujlwm no siv MAX7219 8x8 LED module. Nws yog ib qho yooj yim heev rau siv.

Kuv xav qhia tias vim muaj coob tus txuas xov tooj ntawm txoj haujlwm no, nws yuav suav tias yog INTERMEDIATE qib Qhia.

Cia peb pib!

Khoom siv

Elegoo Starter Kit Cov Khoom Siv (https://rebrand.ly/dvjb3w8)

  • UNO R3 Microcontroller
  • MAX7219 8x8 LED Module
  • LCD 16x2 Zaub Module
  • 10K Trim Potentiometer thiab pob qhov rooj
  • Dupont Hlau
  • 220R tus neeg tiv thaiv
  • Passive Piezo Buzzer
  • Cov Khoom Siv Hluav Taws Xob
  • 9V 1A Adapter - xav tau vim UNO tsis tuaj yeem muab cov khoom siv txaus rau 8x8 LED Module
  • Cov qhob cij

Xav Tau Cov Khoom Ntxiv

2 x 10K Linear Potentiometer - pheej yig thiab dav muaj nyob ntawm eBay, AliExpress, Banggood thiab lwm yam.

Kauj Ruam 1: Txuas Lub Circuit Court

Kev tiv thaiv kab mob
Kev tiv thaiv kab mob

Txhim kho lub voj voog raws li daim duab qhia kab. Siv koj lub sijhawm. Muaj ntau qhov kev sib txuas xav tau rau ob qho kev qhia.

Daim ntawv ceeb toom hauv daim duab ntawm kab lus hais tias lub zog hloov pauv tau txuas rau sab laug ntawm lub khob cij thiab 9V 1A DC Adapter tau txuas rau hauv lub zog hluav taws xob kom txaus tam sim no tau muab rau hauv LED matrix. Tsis muaj kev sib txuas ntawm 5V tus pin ntawm UNO thiab lub khob cij. TAB SIS, GND tus pin ntawm UNO txuas nrog GND ntawm lub khob cij.

Ob npaug thiab triple-xyuas koj cov haujlwm.

Kauj ruam 2: Arduino Code

Cov lus qhia no xav tias koj twb paub yuav ua haujlwm li cas hauv Arduino.

Rub tawm daim duab txuas nrog Arduino. Nco ntsoov tias koj tau ntxiv hauv LedControl lub tsev qiv ntawv rau koj lub tsev qiv ntawv Arduino. Kuv siv qhov version los ntawm Eberhard Fahle. Tsuas yog tshawb nrhiav MAX7219 hauv Kev Tswj Cov Tsev Qiv Ntawv thiab koj yuav pom thiab nruab nws.

Nco ntsoov tias cov ntawv pitches.h nyob hauv koj daim duab qhia chaw. Nws tau siv los ua suab nrov hauv qhov kev ua si.

Me ntsis txog sijhawm

Raws li kev ncua () hais kom ua tag nrho ncua kev ua tiav ntawm koj daim duab thaum nws ua haujlwm, peb hloov mus rau lub sijhawm dhau los kom tshwm sim thaum peb xav ua qhov ua kom muaj nuj nqis cuam tshuam nrog cov duab. Peb saib rau lub sijhawm ua ntej dhau los ua ntej peb ua ntu ntu ntawm daim duab xws li hloov kho qhov chaw ntawm lub pob ntawm cov zaub.

Qhov tseem ceeb dua, ncua () hais kom ua yog tsuas yog ua tiav hauv lub voj () qauv. Feem ntau nws tsis ua raws li qhov xav tau hauv lwm txoj hauv kev. Yog li txhua lub sijhawm cuam tshuam txog kev ua yeeb yaj kiab tau ua tiav hauv lub voj () txheej txheem.

Piv txwv:

Peb txhais qee qhov 'ntev' hom kev hloov pauv thiab ob peb ntawm booleans thiab tom qab ntawd teeb lawv tom kawg ntawm teeb tsa ().

bThresh = 80; // lub sijhawm hauv milliseconds ntawm pob hloov tshiab

ballTime = millis (); // teeb tsa lub sijhawm tam sim no

bon = tsis tseeb; // yog lub pob LED qhib lossis tua

ballReturn = tsis tseeb; // peb puas rov qab pob tom qab ntaus duav?

Hauv lub voj () rau kos lub pob peb muaj:

yog ((millis () - ballTime> bThresh) && bon == tsis tseeb) {// yog tias lub pob OFF thiab lub sijhawm txaus dhau los ntawm BallOn (); // qhib lub pob LED

bon = muaj tseeb; // lub pob tam sim no ON

ballTime = millis (); // rov pib ballTime rau lub sijhawm tam sim no

}

yog ((millis () - ballTime> bThresh) && bon == muaj tseeb) {// yog tias lub pob qhib thiab txaus sijhawm dhau los

ballOff (); // tua lub pob LED

bon = tsis tseeb; // lub pob tam sim no OFF

ballTime = millis (); rov pib ballTIme rau lub sijhawm tam sim no

}

Muaj ntau txoj hauv kev los ua qhov kev ua si no. Cov no tsuas yog kuv nyiam.

Cov duab kos tau sau tseg tag nrho yog li kuv caw koj nyeem cov cai kom pom tias nws ua haujlwm li cas.

Txheeb, sau thiab xa koj cov cai.

Txaus siab rau ua si koj cov game!

Kauj Ruam 3: Xaus

Xaus
Xaus
Xaus
Xaus

Kuv ua tsaug rau Elegoo Inc rau muab cov khoom siv pib siv hauv qhov haujlwm no. Nws yog cov khoom siv nrog ntau yam loj ntawm ntu thiab cov qauv uas yuav ua rau koj zoo rau hauv Arduino Maker ntiaj teb.

Pom zoo: