Cov txheej txheem:

Whack-a-moLED !!: 7 Kauj Ruam
Whack-a-moLED !!: 7 Kauj Ruam

Video: Whack-a-moLED !!: 7 Kauj Ruam

Video: Whack-a-moLED !!: 7 Kauj Ruam
Video: Whack-A-Mole | Cartoon-Box 22 2024, Kaum ib hlis
Anonim
Whack-a-moLED !!
Whack-a-moLED !!
Whack-a-moLED !!
Whack-a-moLED !!

Tinkercad Cov Haujlwm »

Qhov no yog LED version ntawm Whack-a-Mole Game classic.

Yeej ib txwm siv LED tawm ntawm 4 LEDs hloov lub teeb pom ntawm lub qhov thiab cov neeg ua si tua lub LED siv lub joystick tsis txhob tsoo lub mole!

Khoom siv

Arduino Uno/Nano lossis txhua lub rooj sib txawv

4 LEDs thiab sib xws tam sim no txwv cov resistors.

Joystick module nrog X, Y cov txiaj ntsig

Active Buzzer (yeem)

Jumper xov hlau.. txaus kom debug!

Kauj Ruam 1: Nqa mus rau Circuit

Hook Up lub Circuit Court
Hook Up lub Circuit Court

Nqa mus rau Arduino Uno board rau joystick module, txuas 2 analog Input pins rau X Y cov txiaj ntsig ntawm joystick.

4 LEDs kom txuas nrog siv tus tiv thaiv rau 4 Cov Digital lossis Analog tso tawm pins pins.

Active Buzzer kom txuas nrog tus lej pin

Kauj Ruam 2: Txoj Cai rau Teeb Pins

int xVal = 0, yVal = 0, butVal = 0, xPin = A0, yPin = A1, joyPin = 13, butPin = 7, speakerPin = 9;

int leftLED = A2, rightLED = A3, topLED = A4, hauv qab LED = A5;

int xaiv LED = 0; // Yuav yog ib qho ntawm A2, A3, A4 lossis A5

void teeb tsa () {

pinMode (xPin, INPUT);

pinMode (yPin, INPUT);

pinMode (sab laug LED, OUTPUT);

tus pinMode (rightLED, OUTPUT);

tus pinMode (topLED, OUTPUT); pinMode (hauv qab LED, OUTPUT);

pinMode (joyPin, OUTPUT);

tus pinMode (buzzerPin, OUTPUT);

}

Kauj Ruam 3: Txoj Cai rau Joystick Sensing

void joystickSenseRoutine ()

{

xVal = analogRead (xPin); yVal = analogRead (yPin); butVal = digitalRead (butPin);

joyPin = mapXYtoPin (xVal, yVal, butVal);

analogWrite (xaiv LED, 1024);

yog (xaiv LED! = leftLED) {analogWrite (leftLED, 0); } yog (xaiv LED! = rightLED) {analogWrite (rightLED, 0); }

yog (xaiv LED! = topLED) {analogWrite (topLED, 0); }

yog (xaiv LED! = bottomLED) {analogWrite (bottomLED, 0); }

yog (joyPin == xaiv LED) // Mole Whacked

{

analogWrite (xaiv LED, 0);

//

// Ntxiv cov lej los ua suab paj nruag/suab rau whacking moLED !!

//

}

}

int mapXYtoPin (int xVal, int yVal, int butVal) {if ((xVal <100) and (yVal 400)) {return bottomLED; }

lwm yog ((xVal> 900) thiab (yVal 400)) {rov qab topLED; }

lwm yog ((xVal 400) thiab (yVal <100)) {rov qab sab laug; }

lwm yog ((xVal 400) thiab (yVal> 900)) {rov qab rightLED; }

lwm {rov qab -1; }

}

Kauj Ruam 4: Txoj Cai Loop Txoj Cai Loj

void voj () {

rau (int kuv = 0; kuv <ntev; kuv ++)

{

yog (random (0, 100)> 90) {xaiv LED = anaPinMap (random (2, 6)));}

// Ntxiv code rau game game ntawm no

// *** *** ***

//

}

int anaPinMap (int randNum) {

yog (randNum == 2) {xa A2; }

lwm tus yog (randNum == 3) {rov qab A3; }

lwm tus yog (randNum == 4) {xa A4; }

lwm tus yog (randNum == 5) {rov qab A5; }

}

Kauj Ruam 5: Npaj Mus Sim

Kauj Ruam 6: Kev Siv Arduino Nano rau Prototype

Image
Image

Kev siv tib yam ua nrog Arduino nano hauv daim ntawv qhia zaub mov, kev cai ua lub rooj tsavxwm nrog LEDs, tiv thaiv thiab buzzer, thiab X-Y joystick hloov.

Kauj Ruam 7: Kawg Ntim Whack-a-MoLED Prototype los nthuav qhia Koj Tus Hlub

Thaum kawg Ntim Whack-a-MoLED Prototype los nthuav qhia Koj Tus Hlub!
Thaum kawg Ntim Whack-a-MoLED Prototype los nthuav qhia Koj Tus Hlub!
Thaum kawg Ntim Whack-a-MoLED Prototype los nthuav qhia Koj Tus Hlub!
Thaum kawg Ntim Whack-a-MoLED Prototype los nthuav qhia Koj Tus Hlub!

Cov khoom siv rau tsab ntawv:

Lub thawv ntawv yooj yim (Yam tsawg kawg 4cmX6cmX3cm), cov duab los qhia ntxiv los ntawm kev txhawb nqa.

Hniav ntawv rau npog chassis (yeem)

Multipurpose nplaum/kua nplaum

Mini breadboard (yeem)

Arduino nano cov

Me me Universal PCB

9V roj teeb rau lub zog Arduino nano (txuas rau Vin tus pin).

SPDT hloov

Cov khoom siv so (LEDs, tiv thaiv, joystick, buzzer, xov hlau) raws li tau piav qhia hauv theem 1 saum toj no.

Pom zoo: