Cov txheej txheem:
- Kauj Ruam 1: Yam Koj Yuav Tsum Tau
- Kauj Ruam 2: Lub Tsev: Lub Console Hub, Teeb Lub Shield
- Kauj Ruam 3: Lub Tsev: Console Hub, Xaim Lub Shield
- Kauj Ruam 4: Lub Tsev: Tus Tswj, Teeb Koj Qhov Chaw
- Kauj Ruam 5: Tsis teb los tau: Cov ntawv thaiv
- Kauj Ruam 6: Programming: Arduino
- Kauj ruam 7: Programming: HTML
- Kauj ruam 8: Programming: P5.js thiab Javascript
- Kauj Ruam 9: Khiav Koj Txoj Haujlwm
- Kauj ruam 10: Mus Ntxiv
Video: Arduino Controllers: 10 Kauj Ruam (nrog Duab)
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:29
Ib qho Arduino game controller system siv Arduino thiab p5.js library. Cov kev sib txuas ntawm cov tswj tau tsim los siv ntau pawg ntawm ntau yam khoom siv thiab cov tswv yim uas tuaj yeem sib pauv tau nyob ntawm txhua tus tswj.
Txoj haujlwm no tseem tsim los siv p5.js JavaScript tsev qiv ntawv nrog rau p5.play tsev qiv ntawv tsim rau p5.js. Cov tsev qiv ntawv no tso cai rau peb tsim kho peb cov game tau yooj yim. P5.play lub vev xaib muaj cov pawg qhia thiab piv txwv rau cov neeg siv los tsim kev ua si rau nws. Txoj haujlwm no tso cai rau cov neeg siv los xyaum lawv cov txuj ci kho vajtse thiab software.
Kauj Ruam 1: Yam Koj Yuav Tsum Tau
Cov Cuab Yeej:
- Soldering Hlau
- Solder
- Hlau Strippers
- Sab txiav
- Pliers
Kho vajtse:
- Pawg tswj hwm Arduino sib xws (Kuv siv Sparkfun Redboard nrog rau Arduino Uno thiab Leonardo)
-
Pawg Thawj Coj:
- 8cm x 6cm ntsuab perft cam
- Aduino Uno ntaub thaiv npog perf board
-
Ntau yam Sensors
- Joysticks
- Khawm (nrog resistors, 10k ohms, mus nrog lawv)
- Potentiometers
- Flex Sensors
- Siab Sensors
- Lwm yam…
-
Hlau:
- Tib Hlau (Kuv siv 26 AWG Khoom)
- Ribbon hlau thiab crimps
- So Tawm Headers (Tsawg kawg 20 ntawm cov no)
-
Xaiv Cov Khoos Phis Tawj (koj tuaj yeem siv cov duab los qhia thiab kub kub/zauv sib txuas ua ke):
- Breadboard thiab jumper cables rau prototyping
- 3D Printed enclosures
- Kho vajtse nrawm (Kuv siv M2.5 screws)
Software:
- Arduino IDE Cov
-
p5.js qiv
P5.play tsev qiv ntawv ib yam
- p5.serialcontrol
- Node.js
Kauj Ruam 2: Lub Tsev: Lub Console Hub, Teeb Lub Shield
Solder lub taub hau rau Arduino Uno shield perf board.
- Kuv pib nrog cov ntaub thaiv npog taub hau (lub zog, analog hauv, thiab digital)
- Tom ntej no yog 2x5 header pins. Koj tuaj yeem siv 2x5 lub taub hau, lossis tsuas yog 2 kab ntawm 5 tawg tawm lub taub hau. Kuv tau ua cov kab no nrog A3 thiab A4 ntsug, thiab sab laug 2 qhov chaw nyob nruab nrab ntawm lawv.
Kauj Ruam 3: Lub Tsev: Console Hub, Xaim Lub Shield
Tom ntej no, peb xav taug peb cov xov hlau ntawm daim ntaub thaiv. Nws yooj yim dua los siv cov xov hlau nyob rau sab saum toj, tab sis yog tias koj xav tau kev saib kom huv koj tuaj yeem khiav lawv hauv qab.
Koj xav tau them sai sai rau cov phiaj xwm (Eagle schematic muaj rau rub tawm) thaum ua cov xov hlau no. Koj tseem tuaj yeem saib phau ntawv qhia xim los pab koj txog qhov no.
Lub tswv yim ntawm daim thaiv tsim no yog tso cai 3 cov tswv yim sib xws thiab 5 cov tswv yim digital los ntawm txhua tus tswj. Qhov no ua tiav kom tau txais txiaj ntsig ntawm txhua qhov kev nkag mus sib piv ntawm Arduino Uno ntxiv rau cov xov hlau txuas ntxiv ntawm peb cov xov kab.
Kauj Ruam 4: Lub Tsev: Tus Tswj, Teeb Koj Qhov Chaw
Thawj kauj ruam los tsim koj li kev tswj hwm yog los npaj cov sensors uas yuav siv. Hauv kuv qhov piv txwv, Kuv muaj tus qauv zoo nkauj tswj nrog tus joystick thiab ob peb lub khawm. Kuv kuj muaj tus tswj nrog ob lub zog potentiometers.
Yog tias koj xav rov ua qhov no, koj tuaj yeem saib kuv cov duab rau kev tso kawm.
Cov kauj ruam tom ntej yog txhawm rau txuas koj daim kab xev txuas rau lub rooj tsav tsheb.
- Saj thiab tin lub ribbon cable
- Muab cov hlua kab xev tso rau sab saum toj nruab nrab ntawm koj lub rooj tsav tsheb.
Cov kauj ruam tom ntej yog taug koj cov xov hlau. Kuv pib los ntawm xaim lub zog (5V/xaim liab) thiab hauv av (xaim xim av) rau cov ntsuas ua ntej. Tom qab ntawd kuv tau txuas cov khoom siv analog. Kuv pom nws yooj yim siv cov kab liab kab liab (Analog A0 lossis A3) rau kab rov tav txav mus thiab kab daj (Analog A1 lossis A4) rau kev txav mus los.
Txhawm rau ua kom txhua yam zoo ib yam, Kuv kuj tseem khawm lub pob me me kom liab doog ntawm txhua tus tswj kuv. Qhov no muaj txiaj ntsig zoo rau yam xws li kaw qhov chaw nres nkoj txuas (Kuv yuav hla qhov no tom qab) ntxiv rau cov ntawv qhia zaub mov lossis xaiv.
Kuv tau tshaj tawm cov txheej txheem nrawm ntawm kuv tus joystick maub los yog tias koj xav saib qhov no. Los ntawm peb daim duab qhia tus pin, koj tuaj yeem pom qhov muaj peev xwm ntawm txhua tus tswj kev sib txuas (3 analog inputs, thiab 5 digital).
Kauj Ruam 5: Tsis teb los tau: Cov ntawv thaiv
Cov kauj ruam no yog nyob ntawm yeem, tab sis yog tias koj nkag mus rau lub tshuab luam ntawv 3D qhov txiaj ntsig ntawm koj txoj haujlwm yuav zoo dua me ntsis ntxiv thiab ua tiav. Raws li koj tuaj yeem pom hauv kuv daim ntawv pov thawj, kuv tau siv daim ntawv yooj yim los tiv thaiv cov pob qij txha txuas rau hauv qab ntawm cov laug cam los ntawm poking koj cov ntiv tes.
Koj tuaj yeem pom kuv cov qauv 3D txuas nrog rau theem no. Kuv tau tsim cov ntawv thaiv rau lub hub rau ob qho tib si Arduino Uno/Leonardo thiab Sparkfun RedBoard (pawg thawj coj no tau dav dua thiab siv mini USB).
Rau cov tswj, koj tuaj yeem xa cov no nrog M2.5 screws. Kuv khaws cov txiv ntoo ntawm ib sab ntawm PCB thiab siv lub tshuab ntxhua khaub ncaws thiab cov ntsia hlau rau hauv qab.
Kuv kuj tau suav nrog tus qauv 3D rau lub pob qhov rooj slider rau cov potentiometers kuv tau siv.
Koj tuaj yeem pom txhua daim ntawv 3D ntawm GitHub.
Kauj Ruam 6: Programming: Arduino
Cia peb pib los ntawm teeb tsa tus qauv yooj yim los sim. Kuv hais qhia siv kev qhia tsim los ntawm ITP ntawm NYU pom ntawm no. Txhawm rau ua qhov kev qhia no, koj yuav tsum muaj p5.serialcontroll thiab node.js teeb tsa. Hauv qhov kev qhia no, koj yuav raug qhia rau teeb tsa Arduino kom xa cov ntaub ntawv tseem ceeb uas siv tau los ntawm peb lub tsev qiv ntawv javascript, p5.js. Koj tuaj yeem siv lub hub thiab tus tswj peb tau tsim hauv cov kauj ruam dhau los ua qhov no, lossis koj tuaj yeem rov ua cov kab hluav taws xob uas tau qhia hauv qhov kev qhia. Phau ntawv qhia no siv A0 analog tus lej nkag ntawm Arduino Uno uas tau teeb tsa rau kab xev txiv kab ntxwv ntawm koj thawj tus tswj.
Cov lus qhia tom ntej koj yuav xav ua raws tuaj yeem pom ntawm no. Phau ntawv qhia no yuav coj koj los ntawm teeb tsa ntau yam kev nkag mus thiab siv lawv hauv p5.js. Hauv kev qhia, siv cov tswv yim analog A0 thiab A1. Cov no yuav sib haum rau cov txiv kab ntxwv thiab kab daj ntawm tus tswj 1 ntawm peb qhov system.
Thaum koj tau dhau los ntawm cov lus qhia saum toj no, peb tuaj yeem tsim kho Arduino. Cov cai peb xav siv yog hauv qab no:
// controller 1const int dig2 = 2; // xiav const int dig3 = 3; // ntshav const const dig4 = 4; // gray const int dig5 = 5; // dawb const int dig6 = 6; // dub // maub los 2 const int dig7 = 7; // xiav const int dig8 = 8; // ntshav const const dig9 = 9; // gray const int dig10 = 10; // dawb const int dig11 = 11; // dub
void teeb tsa () {
Serial.begin (9600); thaum (Serial.available () <= 0) {Serial.println ("nyob zoo"); // xa cov lus pib qeeb (300); // tos 1/3 thib ob} pinMode (dig2, INPUT); pinMode (khawb 3, INPUT); pinMode (khawb 4, INPUT); pinMode (khawb 5, INPUT); pinMode (khawb 6, INPUT); pinMode (khawb 7, INPUT); pinMode (khawb 8, INPUT); pinMode (khawb 9, INPUT); pinMode (khawb 10, INPUT); pinMode (khawb 11, INPUT); }
void voj () {
yog (Serial.available ()> 0) {// nyeem cov byte nkag: int inByte = Serial.read (); // nyeem lub sensor:
// ANALOG Controller 1
int analog0 = analogRead (A0); int analog1 = analogRead (A1); int analog2 = analogRead (A2); // ANALOG Controller 2 int analog3 = analogRead (A3); int analog4 = analogRead (A4); int analog5 = analogRead (A5); // DIGITAL Controller 1 int digital2 = digitalRead (dig2); int digital3 = digitalRead (dig3); int digital4 = digitalRead (khawb 4);
int digital5 = digitalRead (khawb 5);
int digital6 = digitalRead (khawb 6); // DIGITAL Controller 2 int digital7 = digitalRead (dig7); int digital8 = digitalRead (dig8); int digital9 = digitalRead (dig9); int digital10 = digitalRead (dig10); int digital11 = digitalRead (dig11); // luam tawm cov txiaj ntsig: Serial.print (analog0); // [0] Serial.print (","); Serial.print (analog1); // [1] Serial.print (","); Serial.print (analog2); // [2] Serial.print (","); // Pib Tswj 2 cov ntaub ntawv Serial.print (analog3); // [3] Serial.print (","); Serial.print (analog4); // [4] Serial.print (","); Serial.print (analog5); // [5] Serial.print (","); Serial.print (digital2); // [6] Serial.print (","); Serial.print (digital3); // [7] Serial.print (","); Serial.print (digital4); // [8] Serial.print (","); Serial.print (digital5); // [9] Serial.print (","); Serial.print (digital6); // [10] Serial.print (","); // Pib tswj 2 cov ntaub ntawv Serial.print (digital7); // [11] Serial.print (","); Serial.print (digital8); // [12] Serial.print (","); Serial.print (digital9); // [13] Serial.print (","); Serial.println (digital10); // [14] Serial.print (","); Serial.println (digital11); // [15]}}
Txoj cai no xa cov ntaub ntawv tseem ceeb los ntawm ob qho ntawm peb cov tswj hwm raws li cov lej ntawm 16 tus lej. Thawj 6 ntawm cov lej no yog peb cov tswv yim sib piv (suav txij 0-1023) thiab 10 qhov tseem ceeb yog peb cov txiaj ntsig digital (0 lossis 1).
Thaum peb cov lej tau muab tso rau, peb tuaj yeem sim qhov no los ntawm kev qhib lub koos pij tawj saib thiab ntaus tus nqi rau hauv peb cov ntawv saib raws li peb tau ua hauv ntu 2 los ntawm ITP. Peb yuav tsum tau txais txoj hlua ntawm peb qhov txiaj ntsig sib cais los ntawm tus lej.
Kauj ruam 7: Programming: HTML
Thaum peb tau txais peb Arduino teeb tsa thiab ua haujlwm, peb tuaj yeem pib tsim peb lub vev xaib. Tus lej HTML yog yooj yim heev.
lub cev {padding: 0; pem: 0;.
Cov cai html yooj yim txuas peb cov ntaub ntawv javascript ua ke. Feem ntau ntawm peb cov cai yuav tshwm sim hauv peb daim duab.js cov ntaub ntawv.
Kauj ruam 8: Programming: P5.js thiab Javascript
Thaum peb muaj peb cov HTML teeb tsa, peb tuaj yeem ua haujlwm ntawm peb JavaScript. Yog tias koj tseem tsis tau tam sim no koj yuav tsum rub tawm p5.js ntxiv rau p5.play thiab ntxiv cov no rau hauv koj lub tsev qiv ntawv tais ceev tseg hauv cov npe rau koj lub vev xaib.
- p5js ua
- p5.o ua
Hauv peb cov kauj ruam dhau los, peb teeb tsa peb cov ntawv HTML kom hu peb p5.js thiab p5.play qiv. Peb kuj teeb tsa nws los siv peb daim duab sketch.js uas yog qhov uas peb yuav ua feem ntau ntawm peb cov phiaj xwm. Hauv qab no yog cov cai rau peb lub cev pob txha. Koj tseem tuaj yeem pom nws ntawm no.
// Serial Variablesvar cov lej; // sib txawv los tuav ib qho piv txwv ntawm lub tsev qiv ntawv serialport var portName = 'COM4'; // sau koj lub npe chaw nres nkoj ntawm no // Ntiaj teb Game Variables ---------------
// Teeb muaj nuj nqi ----------------------
muaj nuj nqi teeb tsa () {createCanvas (640, 480); serial = tshiab p5. SerialPort (); // ua ib qho piv txwv tshiab ntawm lub tsev qiv ntawv serialport serial.on ('npe', printList); // teeb tsa kev hu rov qab rau cov npe txheej xwm txheej xwm txheej serial.on ('txuas nrog', serverConnected); // hu rov qab rau kev txuas mus rau server server.on ('qhib', portOpen); // hu rov qab rau qhov chaw nres nkoj qhib serial.on ('cov ntaub ntawv', serialEvent); // callback rau thaum cov ntaub ntawv tshiab tuaj txog serial.on ('yuam kev', serialError); // hu rov qab rau qhov ua yuam kev serial.on ('kaw', portClose); // hu rov qab rau qhov chaw nres nkoj kaw serial.list (); // sau cov npe chaw nres nkoj serial.open (portName); // qhib qhov chaw nres nkoj txuas} // Kos Duab ----------------------- kos duab kos () {keeb kwm yav dhau (0); // keeb kwm yav dhau dub} // Txhais cov ntaub ntawv xov xwm ntawm no ---------- ua haujlwm serialEvent () {// nyeem ib txoj hlua los ntawm qhov chaw nres nkoj txuas // kom txog thaum koj tau txais kev xa rov qab thiab kab ntawv tshiab: var inString = serial. readStringUntil ('\ r / n'); // kos kom pom tias muaj qhov teeb meem tiag tiag nyob ntawd: yog (inString.length> 0) {yog (inString! == 'nyob zoo') {// yog tias koj tau txais nyob zoo, tsis quav ntsej nws cov sensors = cais (inString, ', '); // faib txoj hlua ntawm tus lej yog (sensors.length> 16) {// yog tias muaj kaum rau lub ntsiab lus (6 analog, 10 digital) // Siv cov ntaub ntawv sensor ntawm no:
}
} serial.write ('x'); // xa ib byte thov cov ntaub ntawv ntau ntxiv}} // tau txais cov npe ntawm cov chaw nres nkoj: ua haujlwm printList (portList) {// portList yog cov npe ntawm cov npe chaw nres nkoj rau (var i = 0; i <portList.length; i ++) {// Zaub cov npe console: print (i + "" + portList ); }} muaj nuj nqi serverConnected () {print ('txuas nrog server.'); } muaj nuj nqi portOpen () {print ('qhov chaw nres nkoj txuas tau qhib.')} ua haujlwm serialError (yuam kev) {luam tawm ('Ib yam dab tsi mus tsis ncaj ncees lawm nrog qhov chaw nres nkoj.' + yuam kev); } muaj nuj nqi portClose () {print ('Qhov chaw nres nkoj kaw.'); } muaj nuj nqi kawCode () {serial.close (portName); rov null; } window.onbeforeununload = kaw qhov chaws;
Thaum koj muaj lub cev pob txha tau txais kev cawmdim. Koj tuaj yeem siv cov txiaj ntsig zoo ib yam li nws tau ua tiav hauv ITP kev qhia. Txoj hlua ntawm qhov muaj txiaj ntsig peb xa los ntawm peb Arduino hauv qib 6 tau raug xa mus raws li kab lus ntawm 16 tus lej. Hauv qab no yog qhov uas peb cais cov kab no.
// Txhais cov ntaub ntawv xov xwm ntawm no ----------
muaj nuj nqi serialEvent () {// nyeem ib txoj hlua los ntawm qhov chaw nres nkoj txuas // kom txog thaum koj tau txais kev xa rov qab thiab kab ntawv tshiab: var inString = serial.readStringUntil ('\ r / n'); // kos kom pom tias muaj qhov teeb meem tiag tiag nyob ntawd: yog (inString.length> 0) {yog (inString! == 'nyob zoo') {// yog tias koj tau txais nyob zoo, tsis quav ntsej nws cov sensors = cais (inString, ', '); // faib txoj hlua ntawm tus lej yog (sensors.length> 16) {// yog tias muaj kaum rau lub ntsiab lus (6 analog, 10 digital) // Siv cov ntaub ntawv sensor ntawm no:}} serial.write ('x'); // xa ib byte thov cov ntaub ntawv ntau ntxiv}}
Tam sim no peb tuaj yeem ua haujlwm peb qhov program kom pom tias nws ua haujlwm!
Kauj Ruam 9: Khiav Koj Txoj Haujlwm
Tam sim no peb tuaj yeem ua haujlwm peb qhov program los saib seb nws puas ua haujlwm. Koj tuaj yeem tsim koj tus kheej game siv skeleton.js cov ntaub ntawv hauv peb cov ntaub ntawv dhau los lossis koj siv qhov yooj yim Yeeb yaj duab game pom ntawm no.
Zoo ib yam li ITP Lab, txhawm rau ua haujlwm peb txoj haujlwm, peb yuav ua raws cov theem hauv qab no.
- Txuas rau hauv Arduino nrog cov tswj (cov) koj npaj yuav siv.
- Qhib p5.serialcontrol
- Hloov koj daim duab p5 qhov chaw nres nkoj mus rau qhov koj siv (yog tias koj siv lub cev pob txha, qhov no yog kab 3)
- Qhib cov ntawv HTML uas txuas rau koj daim duab p5
Yog tias koj muaj xov xwm sab nraud xws li cov duab lossis rub tawm fonts, koj yuav xav khiav qhov no ntawm tus neeg rau zaub mov. Koj tuaj yeem khiav cov neeg rau zaub mov nab nab hauv zos yooj yim yog tias koj xav tau.
Kauj ruam 10: Mus Ntxiv
Txhawm rau mus ntxiv thiab txhim kho kev ua si ntau ntxiv rau qhov no, koj tuaj yeem ua raws ntau yam piv txwv daim ntawv p5.play pom ntawm no. Hauv qab no yog qhov piv txwv ntawm qhov kev ua si nyuaj uas kuv tsim. Nws yog 1 vs 1 tank shooter game. Koj tuaj yeem pom tag nrho cov peev txheej rau nws ntawm GitHub.
Pom zoo:
Yuav Ua Li Cas Thiaj Ua Ntau Tus Game Nrog Arduino Controllers: 6 Kauj Ruam
Yuav Ua Li Cas Thiaj Ua Ntau Tus Neeg Ua Si Nrog Arduino Controllers: Koj puas tau xav tsis thoob tias cov neeg tsim khoom tsim cov kev ua si zoo li cas uas tib neeg thoob ntiaj teb nyiam ua si? Zoo, Hnub no kuv yuav muab rau koj ib qho me me hint txog nws los ntawm kev ua qhov sib tw me me uas yuav raug tswj los ntawm Arduino txuas ntxiv
Cov Duab Duab Duab thiab Cov Duab 1: 4 Cov Kauj Ruam (nrog Duab)
Cov Duab Duab Cubes thiab Cov Duab 1: Thaum sim nrog qee cov ntoo ntoo thiab cov duab los qhia, kuv pom ob peb txoj hauv kev los ua cov voos thiab lwm yam duab los ntawm cov khoom siv yooj yim. Los ntawm kev muab cov no los ua Cov Ntawv Qhia, Kuv vam tias yuav txhawb nqa kev ua si thiab kev kawm. Kev hloov pauv ntawm qhov kev qhia no
Cov Duab Duab Duab Duab, WiFi Txuas - Raspberry Pi: 4 Cov Kauj Ruam (nrog Duab)
Cov Duab Duab Duab Duab, WiFi Txuas - Raspberry Pi: Nov yog txoj hauv kev yooj yim heev thiab tus nqi qis mus rau cov duab thav duab digital - nrog qhov zoo ntawm kev ntxiv /tshem cov duab hla WiFi ntawm 'nyem thiab luag' siv (pub dawb) xa cov ntaub ntawv . Nws tuaj yeem siv tau los ntawm qhov me me £ 4.50 Pi Zero. Koj tseem tuaj yeem hloov pauv
Taw qhia rau Robotics rau Cov Tub Kawm Ntawv Hauv Tsev Kawm Ntawv Nrog Hummingbird Controllers: 18 Cov Kauj Ruam
Taw qhia rau Robotics rau Cov Tub Ntxhais Kawm Hauv Tsev Kawm Ntawv Nrog Hummingbird Controllers: Feem ntau cov cuab yeej neeg hlau ntawm kev ua lag luam niaj hnub no xav kom tus neeg siv rub tawm cov software tshwj xeeb rau hauv lawv lub hard drive. Qhov zoo nkauj ntawm Hummingbird Robotic Controller yog qhov nws tuaj yeem ua haujlwm siv lub vev xaib hauv computer, xws li chromebook. Nws tseem yog
Handheld Console Nrog Wireless Controllers thiab Sensors (Arduino MEGA & UNO): 10 Cov Kauj Ruam (nrog Duab)
Handheld Console Nrog Wireless Controllers thiab Sensors (Arduino MEGA & UNO): Kuv siv dab tsi:- Arduino MEGA- 2x Arduino UNO- Adafruit 3.5 " TFT 320x480 Touchscreen HXD8357D- Buzzer- 4Ohm 3W Speaker- 5mm LED teeb- Ultimaker 2+ Tshuab Luam Ntawv w/ Dub PLA Filament- Lasercutter w/ MDF ntoo- Xim tsuag xim dub (rau ntoo)- 3x nRF24