Cov txheej txheem:

Cyclone LED Arcade Game: 4 Kauj Ruam
Cyclone LED Arcade Game: 4 Kauj Ruam

Video: Cyclone LED Arcade Game: 4 Kauj Ruam

Video: Cyclone LED Arcade Game: 4 Kauj Ruam
Video: Аркадная игра-охотник за светодиодами Arduino Cyclone 2024, Hlis ntuj nqeg
Anonim
Image
Image
Nruab hauv Fixture
Nruab hauv Fixture

Lub hom phiaj ntawm txoj haujlwm no yog tsim kom muaj kev ua si yooj yim siv Arduino uas yuav muaj kev sib tham thiab lom zem rau menyuam. Kuv nco qab Cyclone arcade game yog ib qho ntawm kuv nyiam kev ua si arcade thaum kuv tseem yau, yog li kuv txiav txim siab los theej nws. Qhov no yog txoj haujlwm yooj yim heev uas muaj Arduino, txoj hlua ntawm ib tus neeg ntxim nyiam LEDs, thiab lub laub khawm.

Lub hom phiaj ntawm qhov kev ua si yog kom tsis txhob teeb lub tsheb kauj vab thaum nws mus txog qhov qhia (liab) LED. Yog ua tiav, qib kev nyuaj yuav nce ntxiv. Yog tias tsis ua tiav, lub teeb pom kev yuav rov pib dua ntawm qib nyuaj tam sim no.

Cov lus qhia no yog cov peev txheej loj rau cov tub ntxhais ntawm kuv qhov coding.

Kauj Ruam 1: Sau cov khoom siv

  • Cov Cheeb Tsam Loj:

    • Arduino (Kuv siv UNO)
    • Txoj hlua ntawm tus kheej qhov chaw nyob LEDs (Kuv siv txuas)
    • Laub khawm (Kuv siv txuas)
    • Luam Circuit Court board (PCB) los yog breadboard
    • Cov Khoom Siv Hluav Taws Xob (Kuv siv ob qhov khoom siv hluav taws xob cais, koj tuaj yeem khiav tawm nrog ib qho yog tias koj muaj tswv yim)

      • 5V 3A rau LEDs
      • 9V 1A rau Arduino
  • Moj khaum:

    • Cov cuab yeej hluav taws xob (Kuv hloov kho lub teeb ntoo ntawm Goodwill)
    • LED vaj tsev (Kuv hloov kho koj tus qauv phab ntsa moos thiab drilled qhov siv lub cim qhia feeb raws li qhov cim. Siv lub moos ntoo yog tias ua tau los ua kom yooj yim dua.)
    • Khawm vaj tse (Kuv siv lub luj tshib PVC yeeb nkab)
  • Cov Cuab Yeej / Lwm Yam Khoom:

    • Spare thaiv rau koj Circuit Court
    • 10K (rub-down resistor rau hloov) thiab 470 ohm (rau cov ntaub ntawv xov hlau ntawm LEDs) resistors
    • Laum txhawm rau tsim lub qhov rau koj lub tsev LEDs thiab ua txhua qhov tsim nyog hauv koj lub teeb kom hla cov xov hlau hla
    • Soldering hlau rau soldering koj lub Circuit Court mus rau PCB
    • Phom phom kub kom ruaj ntseg LEDs rau koj lub teeb
    • Velcro lossis qee txoj hauv kev kom ruaj ntseg lub moj khaum ua ke
    • Gaskets xaiv tau rau qhov drilled rau cov xov hlau kom dhau los

Kauj ruam 2: Upload Code

Nco ntsoov koj rub tawm thiab ntxiv "FastLED" lub tsev qiv ntawv

Cov tub ntxhais ntawm txoj cai (tsis muaj lub voj voos) muaj ob lub xeev: thawb khawm siab (Game kawg) thiab thawb khawm qis (Ua Si). Thaum tus neeg siv nias lub pob, LED chaw nyob lub teeb raug tso tseg yog muab piv rau qhov chaw nyob ntawm qhov chaw nruab nrab LED. Yog tias lawv tsis zoo ib yam, txhua lub teeb nyem liab ob zaug thiab qib tam sim no rov pib dua. Yog tias lawv zoo ib yam, lub tog raj kheej (FastLED cov ntawv nyeem ntawv) sau ob zaug, qib kev nyuaj zuj zus, thiab rov ua si dua. Thaum tus neeg ntaus ntawv ntaus qib kawg, lub tog raj kheej ua haujlwm thib yim thiab qhov kev ua si rov pib dua ntawm qib 1.

// Cyclone Game

#suav nrog "FastLED.h" // txog 50 #define NUM_LEDS 40 #define CENTER_LED 21 #define DATA_PIN 7 #define LED_TYPE WS2811 #define COLOR_ORDER RGB // range 0-64 #define BRIGHTNESS 50 // Txhais cov qib nyuaj #define EASY 1 #define MEDIUM 2 #define HARD 3 #define ON_SPEED 4 #define SONIC_SPEED 5 #define ROCKET_SPEED 6 #define LIGHT_SPEED 7 #define MISSION_IMPOSSIBLE 8 // Pib qhov nyuaj rau qhov nyuaj = 1; // Txhais cov kab ntawm leds CRGB leds [NUM_LEDS]; // Puas yog tus neeg uas ua ntawv yeej qhov puag ncig no? Cov ntawv no yog siv rau qhov tsis yooj yim. bool wonThisRound = tsis tseeb; // Pib qhov chaw ntawm lub tsheb kauj vab teeb int LEDaddress = 0; // Puas yog game khiav? bool Ua si = muaj tseeb; // Puas yog thawj qhov yeej? bool CycleEnded = muaj tseeb; // Khawm paub meej const int buttonPin = 9; int buttonState = 0; // Initialize coj lub tsev qiv ntawv thiab arduino ua haujlwm tsis muaj teeb meem teeb tsa () {FastLED.addLeds (leds, NUM_LEDS); FastLED.setBrightness (BRIGHTNESS); pinMode (buttonPin, INPUT); Serial.begin (9600); } // Cov nqaij thiab qos yaj ywm // Ob Hom - Ua Si thiab Xaus Game khoob khoob () yog (buttonState == HIGH) {Ua si = tsis tseeb; // Tus neeg siv tau nias lub pob, thiab LED tau nres ntawm qhov chaw nyob yeej. rau (int kuv = 0; kuv <NUM_LEDS; kuv ++) {leds = CRGB:: Dub; } leds [CENTER_LED] = CRGB:: Liab; leds [LEDaddress] = CRGB:: Ntsuab; FastLED.show (); yog (CycleEnded = tseeb) {int diff = abs (CENTER_LED - LEDaddress); // Pom qhov nrug nruab nrab ntawm lub teeb coj thiab nruab nrab coj yog (diff == 0) {wonThisRound = muaj tseeb; // Player ua tiav yeej qib yog (nyuaj! = MISSION_IMPOSSIBLE) {rau (int i = 0; i <2; i ++) {cylon (); }} yog (nyuaj == MISSION_IMPOSSIBLE) {rau (int i = 0; i <8; i ++) {cylon (); } nyuaj = 0; } nce kev nyuaj (); wonThisRound = tsis tseeb; } lwm {ncua (1000); rau (int kuv = 0; kuv <2; kuv ++) {flash (); }} CycleEnded = tsis tseeb; } LEDaddress = 0; ncua (250); buttonState = digitalRead (buttonPin); yog (buttonState == LOW) {Ua si = muaj tseeb; }} // PLAYING yog (Ua Si) {rau (int i = 0; kuv <NUM_LEDS; kuv ++) {leds = CRGB:: Dub; // Tua tawm tag nrho cov leds} leds [CENTER_LED] = CRGB:: Liab; // Teem chaw nruab nrab coj cov xim rau ntsuab leds [LEDaddress] = CRGB:: Ntsuab; // Teem cyling coj cov xim rau liab FastLED.show (); // Pib pib lub teeb ci LEDaddress ++; // Teeb lub voj voog mus rau ib qho coj ib lub sijhawm yog (LEDaddress == NUM_LEDS) {LEDaddress = 0; } ncua (getTime (nyuaj))); buttonState = digitalRead (buttonPin); yog (buttonState == HIGH) {Ua si = tsis tseeb; CycleEnded = muaj tseeb; }}} // Qib Parameters int getTime (int sib txawv) // Rov qab lub sijhawm qeeb rau coj kev txav chaw ntawm qhov nyuaj {int timeValue = 0; hloov (txawv) {rooj plaub YASY: timeValue = 100; tawg; rooj MEDIUM: timeValue = 80; tawg; rooj plaub HARD: timeValue = 60; tawg; rooj ON_SPEED: timeValue = 40; tawg; rooj SONIC_SPEED: timeValue = 30; tawg; rooj plaub ROCKET_SPEED: timeValue = 20; tawg; rooj LIGHT_SPEED: timeValue = 13; tawg; rooj MISSION_IMPOSSIBLE: timeValue = 7; } rov qab lub sij hawmValue; // Rov qab ncua sijhawm} // Yeej qhov nyuaj nce qhov tsis muaj qhov nce qhov tsis txaus siab () {yog (nyuaj! = MISSION_IMPOSSIBLE && wonThisRound) {nyuaj ++; }} // Poob LED Qhia qhov tsis muaj flash () {fill_solid (leds, NUM_LEDS, CRGB:: Liab); FastLED.show (); ncua (500); fill_solid (leds, NUM_LEDS, CRGB:: Dub); FastLED.show (); ncua (500); } // Yeej LED Qhia qhov tsis muaj fadeall () {rau (int i = 0; kuv <NUM_LEDS; kuv ++) {leds .nscale8 (250); }} void cylon () {zoo li qub uint8_t hue = 0; Serial.print ("x"); // Ua ntej swb tus coj hauv ib qho kev taw qhia rau (int i = 0; i = 0; i--) {// Teem qhov ith coj mus rau liab leds = CHSV (hue ++, 255, 255); // Qhia cov leds FastLED.show (); // tam sim no uas peb tau qhia cov leds, rov pib dua i'th coj mus rau dub // leds = CRGB:: Dub; fadeall (); // Tos me ntsis ua ntej peb ncig ncig thiab ua nws ncua sijhawm ntxiv (10); }}

Kauj Ruam 3: Txhim Kho Hauv Fixture

Nruab hauv Fixture
Nruab hauv Fixture
Nruab hauv Fixture
Nruab hauv Fixture

Kuv yuav tsis mus rau hauv cov ntsiab lus hauv ntu no. Muaj ntau txhiab txoj hauv kev sib txawv los mus txog ntu no thiab kuv xav tias koj yuav tsum muaj tswv yim los ua kom nws zoo li koj nyiam. Uas tau hais tias, lub moos tau yooj yim zoo siv rau vaj tsev LEDs vim nws muaj cov cim qhia feeb uas kuv muaj peev xwm siv los ua cov cim laum. Tsis tas li, daim iav npog kuj tseem tso cai rau kuv siv qhov no ua lub rooj.

Lub velcro tau muaj txiaj ntsig zoo ib yam rau kev nyab xeeb teeb tsa LED rau cov khoom siv hluav taws xob nyob hauv tsev. Kuv kuj siv velcro ntawm Arduino. Qhov no ua rau nws yooj yim heev rau rub Arduino tawm yog tias kuv puas xav hloov kho txoj cai.

Pom zoo: