Cov txheej txheem:

Plug thiab Ua Si Cov Khawm Arcade: 7 Kauj Ruam (nrog Duab)
Plug thiab Ua Si Cov Khawm Arcade: 7 Kauj Ruam (nrog Duab)

Video: Plug thiab Ua Si Cov Khawm Arcade: 7 Kauj Ruam (nrog Duab)

Video: Plug thiab Ua Si Cov Khawm Arcade: 7 Kauj Ruam (nrog Duab)
Video: Ntxoov Yias The Shaman Warrior Part 4 2024, Hlis ntuj nqeg
Anonim
Plug thiab Ua Si Cov Khawm Arcade
Plug thiab Ua Si Cov Khawm Arcade

Kuv nyuam qhuav pib siv Arduino los ua kuv cov haujlwm. Raws li tus tsim qauv Kuv nyiam ua kev cai cuam tshuam rau kuv cov kev ua si/kev sib tham sib tham.

Ib qho teeb meem kuv tau hla qhov uas siv cov lus sib tham yog qhov nyuaj heev thiab muaj teeb meem thiab kab thiab kuv xav tau kev daws teeb meem sai thiab yooj yim los tso cai rau kuv siv cov nyees khawm sab nraud los tswj kuv cov kev ua si.

Raws li kuv xav tau lub ntsaws thiab ua si ntaus ntawv uas koj tuaj yeem siv tam sim nrog txhua lub khoos phis tawj, Kuv yuav Arduino Leonardo. Nws yuav luag zoo ib yam rau Uno, tab sis nrog qee qhov sib txawv. Qhov sib txawv tseem ceeb uas kuv yuav siv rau kuv qhov txiaj ntsig rau txoj haujlwm no yog nws lub peev xwm los ua HID. HID, lossis tib neeg lub cuab yeej siv sib txuas yog USB txheej txheem uas tso cai rau koj lub khoos phis tawj lees paub thiab lees paub cov tswv yim los ntawm cov twj siv hluav taws xob thiab lub khoos phis tawj nas tsis tas yuav teeb tsa cov tsav tsheb tshwj xeeb rau txhua lub cuab yeej.

nco tseg: koj tseem tuaj yeem siv Uno, yog tias koj hloov kho lub firmware, raws li qhia ntawm no.

Kauj ruam 1: Cov ntaub ntawv

Rau qhov haujlwm no koj yuav xav tau:

1x HID peev xwm microcontroller (muaj qee qhov zoo li Arduino micro, Due & leonardo, Kuv yuav siv Arduino Leonardo)

1x USB rau arduino cable (rau Leonardo nws yog USB micro)

3x Arcade nyees khawm (Kuv yuav cov no)

1x solderless breadboard

3 x 10 k ohm resistors

3 x 220 ohm resistors

Jumper xov hlau

Koj tuaj yeem tau ntxiv cov nyees khawm ntxiv, lossis muab txhua yam tso rau hauv lub lauj kaub tais diav kom ua tau yam ruaj khov dua.

Kauj ruam 2: Prototyping

Prototyping
Prototyping
Prototyping
Prototyping
Prototyping
Prototyping

Yog li, ua ntej kuv yuav lub khawm arcade uas kuv xav siv Kuv tau sim qhov no nrog tus qauv thawb khawm. Hlau txuas cov nyees khawm hauv txoj hauv kev, Kuv ntseeg tias kuv siv 10K ohm resistors.

Cov txheej txheem, ua tsaug rau Leonardo, yog qhov yooj yim zoo nkauj. Koj yuav tsum suav nrog Keyboard lub tsev qiv ntawv. Kuv siv tus qauv Arduino piv txwv "Keyboard lus" ua lub hauv paus rau kuv cov cai.

Tam sim no lo lus nug yog koj xav kom koj cov nyees khawm ua haujlwm li cas. Hauv paus koj muaj ob txoj kev xaiv, ib lub nyees khawm nias thiab cov ntawv txuas tas mus li yog thawb. Nws yeej nyob ntawm koj qhov project uas koj xav tau.

Yog tias koj xav tau ib qho piv txwv ntawm ib yam dab tsi tshwm sim yog tias tus yuam sij raug nias, zoo li dhia lossis qhib/tawm hloov ces koj yuav xaiv ib txoj hauv kev thawb. Nrog txoj hauv kev no koj saib lub xeev lub pob, puas yog nws nce lossis nqis? Tom qab ntawd koj piv nws rau lub xeev dhau los, nws puas tau nce lossis nqis? Yog tias lub xeev khawm dhau los zoo ib yam li lub xeev khawm tam sim no tsis muaj dab tsi tshwm sim. Tab sis yog tias lub xeev hloov pauv, ib yam li koj nias lossis tso lub pob kom muaj qee yam tshwm sim. Hauv kuv tus lej nws tsuas yog sau ib tsab ntawv thaum lub pob raug thawb, tsis yog thaum tso tawm tab sis koj tuaj yeem hloov qhov no.

#suav nrog "Keyboard.h"

const int buttonLeft = A0; // tus pin nkag rau lub khawm

const int khawmRight = A1; const int buttonUp = A2;

int yav dhau losButtonStateLeft = HIGH; // rau kev txheeb xyuas lub xeev ntawm lub laub khawm

int yav dhau losButtonStateRight = HIGH; int yav dhau losButtonStateUp = HIGH;

void teeb tsa () {

// ua tus pushButton tus pin nkag: pinMode (buttonLeft, INPUT); pinMode (buttonRight, INPUT); pinMode (buttonUp, INPUT); // pib tswj hwm cov keyboard: Keyboard.begin (); }

void voj () {

// nyeem lub khawm: int buttonStateLeft = digitalRead (buttonLeft); // yog tias lub xeev khawm tau hloov pauv, yog tias ((buttonStateLeft! = previousButtonStateLeft) // thiab tam sim no nws tau nias: && (buttonStateLeft == HIGH)) {// ntaus tawm cov lus Keyboard.print ("a"); } // txuag lub xeev khawm tam sim no rau kev sib piv tom ntej: yav dhau losButtonStateLeft = buttonStateLeft;

// nyeem lub khawm:

int buttonStateRight = digitalRead (buttonRight); // yog tias lub xeev khawm tau hloov pauv, yog tias ((buttonStateRight! = previousButtonStateRight) // thiab nws tam sim no raug nias: && (buttonStateRight == HIGH)) {// ntaus tawm cov lus Keyboard.print ("w"); } // txuag lub xeev khawm tam sim no rau kev sib piv zaum tom ntej: yav dhau losButtonStateRight = buttonStateRight;

// nyeem lub khawm:

int buttonStateUp = digitalRead (buttonUp); // yog tias lub xeev khawm tau hloov pauv, yog tias ((buttonStateUp! = previousButtonStateUp) // thiab tam sim no nws tau nias: && (buttonStateUp == HIGH)) {// ntaus tawm cov lus Keyboard.print ("d"); } // txuag lub xeev khawm tam sim no rau kev sib piv tom ntej: yav dhau losButtonStateUp = buttonStateUp; }

Yog tias koj xav tau qee yam txuas ntxiv tshwm sim tsuav yog lub pob raug thawb, raws li koj xav tau rau sab laug lossis sab xis txav koj, tsuas yog cia nws sau ib tsab ntawv yam tsis tau txheeb xyuas lub xeev khawm yav dhau los. Nco ntsoov ntxiv qhov kev ncua me me txhawm rau tiv thaiv nws los ntawm kev vwm thiab tawm tsam txhua qhov thaws koj cov nyees khawm yuav muaj. Muaj ntau txoj hauv kev los daws qhov teeb meem no, tab sis qhov no yooj yim thiab nrawm.

#suav nrog "Keyboard.h"

const int buttonLeft = A0; // tus pin nkag rau lub khawm

const int khawmRight = A1; const int buttonUp = A2;

void teeb tsa () {

// ua tus pushButton tus pin nkag: pinMode (buttonLeft, INPUT); pinMode (buttonRight, INPUT); pinMode (buttonUp, INPUT); // pib tswj hwm cov keyboard: Keyboard.begin (); }

void voj () {

// nyeem lub khawm: int buttonStateLeft = digitalRead (buttonLeft); yog (buttonStateLeft == HIGH) // yog tias lub pob nyem {// ntaus tawm cov lus Keyboard.print ("a"); ncua (50); // Ncua rau thaws & kom koj lub computer caum tau}

// nyeem lub khawm:

int buttonStateRight = digitalRead (buttonRight); yog (buttonStateRight == HIGH) // yog tias lub pob nyem {// ntaus tawm cov lus Keyboard.print ("w"); ncua (50); // Ncua rau thaws & kom koj lub computer caum tau}

// nyeem lub khawm:

int buttonStateUp = digitalRead (buttonUp); yog (buttonStateUp == HIGH) // yog tias lub pob nyem {// ntaus tawm cov lus Keyboard.print ("d"); ncua (50); // Ncua rau thaws & kom koj lub computer caum tau}}

Koj tuaj yeem siv qhov sib xyaw ntawm ob txoj hauv kev, nyob ntawm seb yam twg zoo tshaj rau koj xav tau.

Kauj Ruam 3: Laser Txiav Cov Ntaub Ntawv

Laser Txiav Case
Laser Txiav Case

Rau rooj plaub kuv siv 3 hli mdf, nrog 2 hli Plexiglas ntxig. Kuv ntxiv qhov ntxig raws li kuv xav ntxiv qee cov LEDs sab hauv ntawm rooj plaub nyob rau theem tom ntej kom nws zoo thiab ci.

Kuv nkag mus rau kuv qhov ntev rau makercase thiab rub tawm cov ntaub ntawv svg. Kuv qhib nws hauv Illustrator thiab ntxiv qhov uas kuv xav tau. Yog tias koj tsis muaj Illustrator koj tuaj yeem siv Inkscape rau theem no.

Koj tsis tas yuav siv lub tshuab txiav laser, vim qhov no yog lub npov yooj yim nrog ob peb qhov hauv nws. Nws yuav tsum yooj yim txaus los tsim nws siv cov cuab yeej siv hluav taws xob ntau dua (lossis txawm tias cov cuab yeej siv tes!) Kuv tsuas yog tub nkeeg thiab tau nkag mus rau lub tshuab txiav laser.

Kauj ruam 4: Soldering Arcade Nyees khawm

Soldering Arcade Nyees khawm
Soldering Arcade Nyees khawm
Soldering Arcade Nyees khawm
Soldering Arcade Nyees khawm
Soldering Arcade Nyees khawm
Soldering Arcade Nyees khawm

Lub pob arcade (lossis tsawg kawg yog kuv li) suav nrog peb ntu. Cov yas yas, tus tuav LED (nrog LED hauv nws) thiab hloov micro. Qhov hloov pauv me me yog qhov khawm ib feem ntawm lub pob thiab yog yam koj yuav xav tau txuas rau koj Arduino. Muaj peb lub dav hlau (cov khoom siv hlau uas tawm, qhov twg koj yuav muab koj cov xov hlau txuas) ntawm lub micro hloov. Qhov nyob saum (lossis hauv qab, yam koj xav tau) yog av. Lwm ob lub davhlau ya nyob twg yog Qhib Li Qub (TSIS MUAJ) thiab Qhib Kaw (NC). TSIS txhais tau tias yog qhov hloov pauv tau nias nws ua rau muaj kev sib txuas. NC txhais tau tias yog tias khawm tau nias nws ua txhaum qhov txuas. Peb yuav siv NO rau qhov haujlwm no. Kuv sau daim av, TSIS YOG thiab NC ntawm kuv qhov hloov pauv micro hauv cov duab.

Kuv cov nyees khawm tau ci ntsa iab yog li kuv tau siv cov xov hlau txuas rau tus tuav LED. Nco ntsoov xim xim koj cov xov hlau kom koj paub tias sab twg yog anode thiab qhov cathode (qhov zoo thiab tsis zoo ntawm LED).

Kuv tau siv lub taub hau taub hau txuas rau kuv cov xov hlau, kom ua rau lawv yooj yim siv nrog lub lauj kaub tais diav uas tsis txhuam. Kuv tsuas yog xaim lub xaim rau lub taub hau taub hau thiab tso me ntsis ntawm cov cua sov ntswj tubing nyob ib puag ncig kom lawv muaj zog dua.

Kauj Ruam 5: Khaws Cov Khawm & Txuas Lawv Rau Koj Lub Rooj Tswjhwm Saib

Khaws Cov Khawm & Txuas Lawv Rau Koj Lub Rooj Tswjhwm Saib
Khaws Cov Khawm & Txuas Lawv Rau Koj Lub Rooj Tswjhwm Saib
Khaws Cov Khawm & Txuas Lawv Rau Koj Lub Rooj Tswjhwm Saib
Khaws Cov Khawm & Txuas Lawv Rau Koj Lub Rooj Tswjhwm Saib
Khaws Cov Khawm & Txuas Lawv Rau Koj Lub Rooj Tswjhwm Saib
Khaws Cov Khawm & Txuas Lawv Rau Koj Lub Rooj Tswjhwm Saib
Khaws Cov Khawm & Txuas Lawv Rau Koj Lub Rooj Tswjhwm Saib
Khaws Cov Khawm & Txuas Lawv Rau Koj Lub Rooj Tswjhwm Saib

Tam sim no nws yog lub sijhawm los teeb tsa koj lub khawm arcade hauv koj rooj plaub. Tshem lub nplhaib xauv los ntawm cov yas yas thiab lo nws hla lub qhov hauv rooj plaub. Xov lub xauv lub nplhaib nyob rau lwm sab kom ruaj ntseg khawm nyob hauv qhov chaw. Khaws rau hauv tus tuav LED thiab ntswj kom nws xauv rau hauv qhov chaw. Qoj hauv qhov hloov pauv me me (muaj me me me me thiab qhov uas sib koom ua ke los tuav nws rau hauv qhov chaw).

Txhawm rau txuas cov hloov pauv mus rau pawg thawj coj saib tshem cov nyees khawm koj tuaj yeem lossis tsis tau ntxiv. Txuas cov hlau ua los ntawm hauv av ntawm micro hloov mus rau hauv av ntawm Arduino thiab tus tiv thaiv (qhov twg txhais ceg ntawm lub laub khawm tau). Txuas cov xaim ua los ntawm NO ntawm lub micro hloov mus rau 5v ntawm Arduino.

Rau cov xov hlau LED txuas cov xaim tsis zoo rau hauv av & qhov zoo ntawm 220OHM tus tiv thaiv mus rau 5v. Yog tias koj xaim lawv li qhov no lawv yuav nyob tas li. Koj tuaj yeem ntxiv lawv hauv cov cai thiab ua rau lawv hloov pauv thiab tawm ua ke nrog cov nyees khawm yog tias koj xav tau.

Kauj Ruam 6: Coding Hell

Yog li, tam sim no koj tau txuas koj lub khawm tshiab zoo nkauj rau koj cov cai qub thiab tam sim ntawd nws tsis ua haujlwm raws li nws xav tau ntxiv. Cov ntawv tshwm ob lossis peb zaug hauv ib lub sijhawm thiab nws tsis ua haujlwm raws li nws yuav tsum tau ua nrog HTML5 kev ua si yooj yim. Txais tos kom debounce ntuj raug txim.

Thawj yam ua ntej. Cov cai peb tau sau thaum tsim qauv? nws ua haujlwm zoo thiab yooj yim, tab sis nws tsis ntxim nyiam. Yog tias koj xav ntxiv cov nyees khawm ntxiv koj yuav tsum theej & paste cov ntawv luv ntawm cov cai thiab hloov txhua qhov txiaj ntsig hauv lawv. Yog tias koj hnov qab ib qho ntawm lawv koj nkag mus rau qhov kho kab laum phem. Tshawb xyuas lub ntsiab lus ntawm no? Coding yog ntuj raug txim, tab sis lom zem heev, daws teeb meem ntuj raug txim.

Peb xav kom zoo nkauj, luv tus lej. Yog li peb yuav hloov tag nrho cov khawm ib tus lej rau hauv arrays. Txoj kev no, yog tias koj xav ntxiv cov nyees khawm ntxiv koj tsuas yog yuav tsum tau hloov lub pob khawm, cov pins uas lawv nyob thiab lawv cov zis. Peb kuj tseem hloov qhov kev nkag mus rau ASCII vim tias … nws ua haujlwm zoo dua?

Tam sim no yog tias koj zoo li kuv koj yuav sau ib txoj hauv kev yooj yim thiab yooj yim siv cov nyees khawm thiab nws yuav tsis ua haujlwm zoo li koj xav tau. Yog li koj tsim cov ntawv tshiab (nco qab cov menyuam, nce ntxiv rov qab!), Sim ntau yam sib txawv, sau tas li cov lej nyuaj uas tseem tsis ua haujlwm zoo thiab thaum kawg rov qab mus rau cov lej yooj yim uas koj tau sau teev dhau los THIAB pom qhov yuam kev me me uas tam sim kho txhua yam.

Cia kuv tseg koj txoj kev taug, ntawm no yog txoj cai ua haujlwm:

Kev tsis lees paub: cov ntawv no tau sau tom qab teev teev thiab kho kab mob yooj yim heev. Thov tsis saib xyuas ib qho cim ntawm kev ntxhov siab thiab tsom mus rau txoj haujlwm ua haujlwm tshaj tawm hauv qab no;)

#suav nrog "Keyboard.h" #define buttonAmount 3

int buttonPin = {

A0, A1, A2}; // Cov nyees khawm nyob qhov twg? int asciiLetter = {97, 100, 119}; // Cov ntawv hauv ASCII, ntawm no: a, d, w int buttonState [buttonAmount]; // Puas yog lub pob raug thawb lossis tsis?

void teeb tsa () {

rau (int i = 0; kuv <buttonAmount; i ++) {// voj voog los ntawm cov kab pinMode (buttonPin , INPUT); // teeb tsa txhua tus pin rau kev nkag mus}}

void voj () {

rau (int i = 0; kuv <buttonAmount; i ++) // mus los ntawm qhov array {buttonState = digitalRead (buttonPin ); // Cov nyees khawm ua dab tsi? yog (buttonState == HIGH) {// Yog tias lub pob raug nias Keyboard.press (asciiLetter ); // xa tsab ntawv sib xws} lwm yam // yog tias lub pob tsis raug nias {Keyboard.release (asciiLetter )); // tso tsab ntawv}}

}

Kauj Ruam 7: Txhua Yam Ua Haujlwm

Txaus siab rau koj lub ntsaws & ua si cov tswj kev cai!

Yog tias koj nyiam qhov kev qhia no, thov txiav txim siab pov npav rau kuv hauv kev sib tw!

Pom zoo: