Cov txheej txheem:

Tsim Tus Kws Tswj Xyuas Lub Cev: 10 Kauj Ruam (nrog Duab)
Tsim Tus Kws Tswj Xyuas Lub Cev: 10 Kauj Ruam (nrog Duab)

Video: Tsim Tus Kws Tswj Xyuas Lub Cev: 10 Kauj Ruam (nrog Duab)

Video: Tsim Tus Kws Tswj Xyuas Lub Cev: 10 Kauj Ruam (nrog Duab)
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Tsim Tus Kws Tswj Lub Cev
Tsim Tus Kws Tswj Lub Cev
Tsim Tus Kws Tswj Lub Cev
Tsim Tus Kws Tswj Lub Cev

Thaum Nintendo Wii tau tshaj tawm cov neeg ua si tau raug txhawb, tsis xav tau, tawm ntawm lub rooj zaum thiab dhia, seev cev, thiab jiggle txhawm rau ua kom tau qhab nia hauv lawv qhov kev xaiv game. Thaum muaj txoj kev kawm nkhaus nkhaus hauv kev tsim rau Wii, nws yooj yim los tsim cov cuab yeej siv uas tso cai rau koj tswj kev ua si los ntawm kev tawm dag zog lub cev dhia ntawm lub ncoo ntawm lub sijhawm.

Cov lus qhia no qhia tau tias kuv hloov kho qhov kev ua si 'Space Bounce' (tuaj yeem ua si nyob ntawm https://marquisdegeek.com/spacebounce/ nrog rau qhov chaw ntawm https://github.com/MarquisdeGeek/SpaceBounce) los siv lub cev tswj.

Khoom siv

  • Arduino
  • Ob lub laub siab (kuv tau los ntawm Maplin
  • Ob tus tiv thaiv, rau lub siab lev (100 K, tab sis feem ntau zoo)
  • Ob LEDs (yeem)
  • Ob tus tiv thaiv, rau LEDs (100 K, tab sis feem ntau yog qhov zoo. Kuj tseem xaiv)
  • Laptop

Kauj ruam 1: Dhia ib ncig

Dhia ib ncig!
Dhia ib ncig!

Kuv pib los ntawm kev tsim tus dhia dhia sib tham thiab, ntawm kev tshuaj xyuas qhov kev ua si, pom tau tias muaj ob lub lev yuav qhia tau zoo tshaj plaws nws lub tswv yim. Ntawd yog, koj sawv ntawm daim lev sab laug los sim qhov kev xav ntawm kev tuav mus rau ntawm phab ntsa sab laug thiab, thaum lub sijhawm tsim nyog, dhia hla mus rau sab xis, thiab koj tus cim ntawm lub vijtsam yuav ua ib yam.

Kauj Ruam 2: Txuas Cov Pads

Txuas Cov Pads
Txuas Cov Pads
Txuas Cov Pads
Txuas Cov Pads

Yog li kuv yuav ob lub lev, thiab tau mus ua haujlwm. Lub mats siab qhia ntawm no yog qhov yooj yim tshaj plaws (thiab pheej yig tshaj!) Kuv pom, ntawm £ 10 txhua. Lawv muaj plaub lub xov hlau, ob qho uas ua haujlwm zoo li hloov pauv yooj yim: thaum koj sawv ntawm lub lev, kev sib txuas tau ua, thiab thaum koj dhia nws nws tau tawg. Kuv pub qhov no rau hauv Arduino nrog qhov yooj yim Circuit Court.

Kauj Ruam 3: Tripping Lub Teeb Zoo

Tripping Lub Teeb Zoo heev
Tripping Lub Teeb Zoo heev

Nws ua haujlwm, tab sis tsis txhawb siab heev. Yog li, kuv tau ntxiv qee qhov LED los qhia txog lub xeev ntawm txhua lub lev siab.

Cov LEDs tsis tas yuav tsum ua qhov kev ua si, tab sis los ntawm kev ntxiv lawv rau hauv Circuit Court Kuv tuaj yeem pom yooj yim qhov kev xav hauv Circuit Court yog lub xeev tam sim no. Yog li ntawd, yog tias qhov kev ua si tsis ua haujlwm raug, kuv tuaj yeem ua haujlwm yog tias qhov teeb meem yog nrog Circuit Court, Arduino software, lossis game logic.

Kauj ruam 4: Pib rau Code

Muab thawj qhov kev ua si yog hauv JavaScript, txiav txim siab kuv sau NodeJS qhov program uas mloog rau kev hloov pauv hauv lub xeev lub lev siab, thiab xa cov ntaub ntawv ntawm websockets mus rau tus neeg siv game.

Ua ntej, teeb tsa tus qauv firmata rau koj Arduino kom peb tuaj yeem ua haujlwm Node server ntawm PC thiab siv Johnny Five lub tsev qiv ntawv los mloog rau lub xeev hloov pauv los ntawm Arduino. Tom qab ntawd ntxiv Express los ua haujlwm cov ntsiab lus game.

Tag nrho cov cai server zoo li no:

const nthuav tawm = xav tau ('nthuav tawm');

const app = nthuav tawm (); const http = xav tau ('http'); const neeg rau zaub mov = http.createServer (app); const io = xav tau ('socket.io'). mloog (server); const arduino = xav tau ('arduino-controller'); server.listen (3000, muaj nuj nqi () {console.log ('Qhia server mloog …');}); app.use ('/', express.static ('app')); const tsib = xav tau ("johnny-five"); const board = tshiab tsib. Board ({repl: false}); board.on ("npaj tau", muaj nuj nqi () {cia ntsuab = tshiab tsib. Led (5); cia liab = tshiab tsib. Led (6); cia sab laug = tshiab tsib. Pin (2); tso cai = tsib tshiab. Pin (3); io.on ('txuas', muaj nuj nqi (socket) {console.log ('Peb txuas nrog!'); Cia lastLeft = tsis tseeb; cia lastRight = cuav; tsib. Pin.read (sab laug, (err, val) => {if (val) {green.on ();} else {green.off ();} if (val! == lastLeft) {lastLeft = val; cia lub xeev = {sab: 'sab laug', xeev: val? 'nqis': 'nce'} socket.emit ('arduino:: state', JSON.stringify (xeev), {rau: 'txhua tus'});}}) tsib. Pin.read (txoj cai, (err, val) => {if (val) {red.on ();} else {red.off ();} // if (val! == lastRight) {lastRight = val; cia lub xeev = {sab: 'txoj cai', xeev: val? 'nqis': 'nce'} socket.emit ('arduino:: xeev', JSON.stringify (xeev), {rau: 'txhua tus'});}}))); });

Thiab ua haujlwm nrog:

node server.js

Kauj Ruam 5: Hloov Kho Game

Thawj qhov teeb meem yog lub interface; ua li cas koj 'nyem' ntawm khawm ua si thaum txhua yam koj tuaj yeem ua yog dhia? Kuv daws qhov no los ntawm kev tshem tawm tag nrho lwm cov nyees khawm! Kuv tuaj yeem ua rau khawm ntxiv thaum twg tus neeg ua si dhia, los ntawm kev mloog rau ib qho 'nce' kev tshwm sim.

qhov (socket) = io (); socket.on ('arduino:: state', muaj nuj nqi (msg) {cia cov ntaub ntawv = JSON.parse (msg); yog (data.state === 'nce') {// peb dhia!}});

Txij ntawm no kuv tuaj yeem nkag mus rau hauv qhov kev ua si, thiab siv cov ntaub qhwv rau qee yam lom zem dua - qhov kev ua si nws tus kheej.

Kauj Ruam 6: Hloov Tus Neeg Ua Si Jump Code

Lub sijhawm no kuv yuav xav tau nrog txhua lub ncoo ib tus zuj zus, thiab ua kom tus cwj pwm pib dhia thaum twg tus neeg ncaws pob txhais taw tawm ntawm lub ncoo. Lub sijhawm rau tus cim ntawm lub vijtsam hla kuv lub taub hau ntev dua li lub sijhawm rau cov neeg ua si dhia ntawm ib sab mus rau ib sab. Qhov no yog qhov zoo, vim nws muab sijhawm rau cov neeg ua si kom rov qab tau txais lawv cov nyiaj tshuav, txheeb xyuas lawv cov taw, thiab saib cov neeg ua si ua tiav dhia ntawm-screen. Yog tias qhov no tsis yog, kuv yuav ua rau tus neeg ua si qeeb.

qhov (socket) = io ();

socket.on ('arduino:: state', muaj nuj nqi (msg) {

cia cov ntaub ntawv = JSON.parse (msg); yog (data.side === 'sab laug' && data.state === 'up') {// peb dhia los ntawm sab laug}});

Kauj Ruam 7: Hloov Cov Lus Tso Tawm

Nrog cov tswv yim ua haujlwm ua haujlwm, Kuv xav tau los ua haujlwm ntawm cov zis. Qhov kev ua si ua si zoo ntawm lub ntsiav tshuaj lossis xov tooj, vim tias nws ua rau lub vijtsam puv. Tab sis, thaum koj dhia ib ncig, nws me me dhau los pom, yog li thaj chaw ua si ntawm lub vijtsam yuav tsum tau nthuav dav. Ntau!

Hmoov tsis zoo, kev nthuav dav tag nrho cov peev txheej duab yog ib txoj haujlwm siv sijhawm ntau heev. Yog li, kuv dag! Txij li qhov kev ua si tsis tas yuav nkag siab X, Y txoj haujlwm ntawm nas nyem, lossis kov qhov xwm txheej, Kuv tuaj yeem rov ntsuas tau yooj yim dua rau tag nrho cov canvas!

Qhov no koom nrog hack ntawm ob qho tib si CSS thiab JavaScript kom cov khoom HTML5 canvas uas twb muaj lawm khiav puv npo.

Tsis tas li ntawd, qhov kev ua si tau ua nyob rau hauv hom duab uas txhais tau tias ua kom siv tau ntau tshaj plaws ntawm lub vijtsam av peb xav tau kom tig daim ntaub los ntawm 90 degrees.

#SGXCanvas {

txoj hauj lwm: meej; z-ntsuas: 0; hloov pauv: tig (-90deg); hloov-keeb kwm: sab saum toj txoj cai; dav: pib; }

Kauj ruam 8: Nws Ua Haujlwm

Nws Ua Haujlwm!
Nws Ua Haujlwm!

Rau kuv thawj qhov kev ua si Kuv qaij kuv lub laptop ntawm nws sab, thiab ua si zoo li no.

Kauj Ruam 9: Npaj Chav

Npaj Chav
Npaj Chav

Tsim lub cev tswj hwm tsuas yog pib ntawm txoj kev taug, tsis yog qhov kawg. Qhov seem ntawm qhov chaw ntawm lub cev yuav tsum tau txiav txim siab.

Ua ntej tshaj, lub laub siab txav mus los rau hauv pem teb thaum koj tsaws rau ntawm lawv. Qhov no tau yooj yim tsau nrog qee daim nplaum ob tog. Lawv ua haujlwm tau zoo, tab sis tej zaum yuav tsis tuav ntau qhov hnav thiab tsim kua muag.

Ntxiv mus, lub khoos phis tawj zoo li ua dag me ntsis, uas cuam tshuam koj ntawm kev ua si nws tus kheej. Yog li, TV los ntawm chaw so tau "qiv" thiab coj mus rau MakerSpace hauv zos, qhov uas nws tau muab tso rau ntawm phab ntsa thiab txuas nrog.

Yav tom ntej nws yuav zoo ntxiv hneev taw rau ntawm lub laub siab (tej zaum Neil Armstrong thawj lub hli luam tawm!) Los coj tus neeg ua si. Kuj zoo dua qhov casing thiab puag ncig rau TV yuav ntxiv rau qhov kev xav. Tej zaum cov uas koj muaj sijhawm ntau thiab ntau qhov chaw tuaj yeem ua daim ntawv mache pob zeb lub ntsej muag, tso rau ntawm ob sab ntawm lub lev, txhawm rau ua raws li claustrophobic zoo li poob ntawm kuv lub taub hau!

Kauj ruam 10: Nws Ua tiav

Thiab muaj koj muaj nws. Txoj haujlwm yooj yim hnub uas txhim kho qhov kev ua si thawj zaug, thiab ua rau koj haum thaum ua si!

Koj kuj tseem tuaj yeem siv Makey Makey uas ncaj qha simulates qhov tseem ceeb siv hauv qhov kev ua si thawj, kom txo qee qhov ntawm txoj haujlwm no. Tab sis qhov ntawd yog qhov ua haujlwm rau tus nyeem ntawv:)

Txhua txoj cai nyob hauv ib ceg tshwj xeeb hauv Space Bounce repo:

Pom zoo: