Cov txheej txheem:

Tus Me Nyuam Tus Cwj Pwm Hloov: 5 Kauj Ruam (nrog Duab)
Tus Me Nyuam Tus Cwj Pwm Hloov: 5 Kauj Ruam (nrog Duab)

Video: Tus Me Nyuam Tus Cwj Pwm Hloov: 5 Kauj Ruam (nrog Duab)

Video: Tus Me Nyuam Tus Cwj Pwm Hloov: 5 Kauj Ruam (nrog Duab)
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Me Nyuam Tus Cwj Pwm Hloov Kho
Me Nyuam Tus Cwj Pwm Hloov Kho

Tus Me Nyuam Tus Cwj Pwm Hloov Pauv ntau npaum li cas koj tus menyuam tau ntsib teeb meem (aka Strikes) thiab thaum lawv mus txog peb, lub suab nrov tawm mus thiab lub vijtsam lcd tshaj tawm tias lawv nyob hauv av.

Kauj Ruam 1: Pib Yooj Yim: Ntxiv Khawm

Pib Yooj Yim: Ntxiv Khawm
Pib Yooj Yim: Ntxiv Khawm

Thawj Kauj Ruam hauv Txoj Haujlwm no yog qhov yooj yim. Ntxiv 1 Khawm. Hauv qib no koj xav tau, 4 Txiv neej rau Txiv Neej Hluav Taws Xob, 1 220 Resisitor thiab lub laub khawm.

  1. Txuas 5V ntawm Sab Fais Fab mus rau kab zoo ntawm lub khob cij
  2. Txuas GND mus rau qhov tsis zoo ntawm lub khob cij

  3. Ntxig lub laub khawm rau ntawm lub khob cij
  4. Txuas lub zog ntawm kab ntawv xa mus rau sab laug hauv qab ntawm lub laub khawm

  5. Hauv av khawm los ntawm kev siv tus tiv thaiv mus rau sab xis hauv qab ntawm lub laub khawm mus rau kab tsis zoo ntawm lub khob cij.
  6. Txuas #13 ntawm Sab Digital ntawm Arduino mus rau sab xis saum toj ntawm lub pob.

Txheeb nrog koj cov cai tias lub pob tau sau npe:

int child1ButtonPin = 13; // Qhov no yog tus pin peb lub laub khawm txuas nrog

int child1ButtonState = 0; // Nyem khawm lub xeev (qhib/tawm)

int child1Strike = 0; // Muaj pes tsawg tus me nyuam ntaus

// teeb tsa muaj nuj nqi ua haujlwm ib zaug thaum koj nias rov pib dua lossis ua haujlwm rau lub rooj tsavxwm

teeb tsa tsis muaj dab tsi () {Serial.begin (9600); pinMode (child1ButtonPin, INPUT); } // lub voj kev ua haujlwm dhau mus thiab ntau dua ib txhis tsis muaj dab tsi voj () {// nyeem lub pob lub xeev (rau lossis tawm) child1ButtonState = digitalRead (child1ButtonPin); yog (child1ButtonState == HIGH) // Nias lub pob {Serial.println ("HIGH"); ncua (5000); }

yog (child1ButtonState == LOW)

{Serial.println ("QIB"); ncua (5000); }}

Kauj Ruam 2: Hloov Kho Txoj Cai rau Sau Npe Khawm Nias

Hloov Kho Txoj Cai rau Sau Npe Khawm Nias
Hloov Kho Txoj Cai rau Sau Npe Khawm Nias
Hloov Kho Txoj Cai rau Sau Npe Khawm Nias
Hloov Kho Txoj Cai rau Sau Npe Khawm Nias

Hloov Kho Txoj Cai txhawm rau sau npe lub pob nyem:

int child1ButtonPin = 13; // Qhov no yog tus pin peb lub laub khawm txuas nrog rau tus menyuam child1ButtonState = 0; // Nyeem lub pob lub xeev (rau/tawm) int child1PreviousState = 0; // Yav dhau los khawm lub xeev int child1Strike = 0;

// teeb tsa muaj nuj nqi ua haujlwm ib zaug thaum koj nias rov pib dua lossis ua haujlwm rau lub rooj tsavxwm

teeb tsa tsis muaj dab tsi () {Serial.begin (9600); pinMode (child1ButtonPin, INPUT); } // lub voj kev ua haujlwm dhau mus thiab ntau dua ib txhis tsis muaj dab tsi voj () {// nyeem lub pob lub xeev (rau lossis tawm) child1ButtonState = digitalRead (child1ButtonPin); if (child1ButtonState! = child1PreviousState) {if (child1ButtonState == HIGH) // Nias lub khawm {child1Strike ++; Serial.println (child1Strike); ncua (1000); }}

}

Tom ntej Hloov Kho Txoj Cai kom tus menyuam tau txais 3 qhov kev tawm tsam tom qab uas lawv yuav tau txais cov lus tias lawv raug tseb:

int child1ButtonPin = 13; // Qhov no yog tus pin peb lub laub khawm txuas nrog rau tus menyuam child1ButtonState = 0; // Nyeem lub khawm lub xeev (rau/tawm) int child1PreviousState = 0; int child1Strike = 0;

// teeb tsa muaj nuj nqi ua haujlwm ib zaug thaum koj nias rov pib dua lossis ua haujlwm rau lub rooj tsavxwm

teeb tsa tsis muaj dab tsi () {Serial.begin (9600); pinMode (child1ButtonPin, INPUT); } // lub voj kev ua haujlwm dhau mus thiab ntau dua ib txhis tsis muaj dab tsi voj () {// nyeem lub pob lub xeev (qhib lossis kaw) child1ButtonState = digitalRead (child1ButtonPin); if (child1ButtonState! = child1PreviousState) {if (child1ButtonState == HIGH) // Nias lub khawm {child1Strike ++; Serial.println (child1Strike);

yog (child1Strike> = 3)

{Serial.println ("Tus Me Nyuam 1 Yog Hauv Qab!"); } ncua (3000); }}

}

Serial Moniter yuav tsum zoo li cov duab saum toj no.

Nco tseg: Nco ntsoov tias koj xis nyob nrog kev ncua sijhawm. Txhawm rau qeeb me ntsis thiab nws yuav sau npe 1 khawm nias ntau dua ib qho!

Kauj Ruam 3: Ntxiv Ntau Khawm Li Koj Muaj Menyuam

Ntxiv Ntau Khawm Li Koj Muaj Menyuam
Ntxiv Ntau Khawm Li Koj Muaj Menyuam
Ntxiv Ntau Khawm Li Koj Muaj Menyuam
Ntxiv Ntau Khawm Li Koj Muaj Menyuam

Hauv cov kauj ruam no, peb tsuas yog luam ob peb kauj ruam kawg. Ntxiv ntau lub nyees khawm ib yam li koj ua menyuam yaus. Hauv kuv qhov xwm txheej, kuv ntxiv plaub. Nco ntsoov hloov koj tus lej tus lej Digital uas lub khawm txuas rau. Hauv kuv qhov xwm txheej kuv siv tus pin 12 txog 10 ntxiv kuv cov nyees khawm. Yog tias koj xav tau kev ceeb toom ntawm no yog Kauj Ruam 1:

  1. Txuas 5V ntawm Sab Fais Fab mus rau kab zoo ntawm lub khob cij
  2. Txuas GND mus rau qhov tsis zoo ntawm lub khob cij

  3. Ntxig lub laub khawm mus rau ntawm lub khob cij txuas lub zog ntawm kab ntawv xa mus rau sab laug hauv qab ntawm lub laub khawm
  4. Hauv av khawm los ntawm kev siv tus tiv thaiv mus rau sab xis hauv qab ntawm lub laub khawm mus rau kab tsis zoo ntawm lub khob cij.

  5. Txuas (koj tus lej tus lej) ntawm Sab Digital ntawm Arduino mus rau sab xis saum toj ntawm lub pob.

Koj kuj tseem yuav tsum hloov kho txoj cai los tswj hwm koj cov nyees khawm. Thov nco ntsoov tias yog koj xav tau ceev faj ntawm Cov hlua uas koj siv. Koj tsis tuaj yeem ntxiv rau cov ntawv qis ua ke. Nws yog qhov zoo tshaj plaws tshaj tawm 1 ua cov khoom siv hlua.

int child1ButtonPin = 13; // Qhov no yog tus pin peb lub laub khawm txuas nrog rau tus menyuam 2ButtonPin = 12; int child3ButtonPin = 11; int child4ButtonPin = 10; int child1ButtonState = 0; // Nyeem lub pob lub xeev (rau/tawm) int child2ButtonState = 0; int child3ButtonState = 0; int tus menyuam4ButtonState = 0; int child1PreviousState = 0; int tus menyuam 2PreviousState = 0; int child3PreviousState = 0; int tus menyuam 4PreviousState = 0; int child1Strike = 0; int tus menyuam 2Strike = 0; int child3Strike = 0; int tus menyuam 4Strike = 0;

// teeb tsa muaj nuj nqi ua haujlwm ib zaug thaum koj nias rov pib dua lossis ua haujlwm rau lub rooj tsavxwm

teeb tsa tsis muaj dab tsi () {Serial.begin (9600); pinMode (child1ButtonPin, INPUT); pinMode (child2ButtonPin, INPUT); pinMode (child3ButtonPin, INPUT); pinMode (child4ButtonPin, INPUT); } // lub voj kev ua haujlwm dhau mus thiab ntau dua ib txhis tsis muaj dab tsi voj () {// nyeem lub pob lub xeev (qhib lossis kaw) child1ButtonState = digitalRead (child1ButtonPin);

child2ButtonState = digitalRead (child2ButtonPin);

child3ButtonState = digitalRead (child3ButtonPin);

child4ButtonState = digitalRead (child4ButtonPin);

yog (child1ButtonState! = child1PreviousState)

{yog (child1ButtonState == HIGH) // Nias lub khawm {child1Strike ++; Serial.println (Txoj hlua ("Menyuam 1 Muaj:") + child1Strike + "ntaus");

yog (child1Strike> = 3)

{Serial.println ("Tus Me Nyuam 1 Yog Hauv Qab!"); } ncua (3000); }} yog (child2ButtonState! = child2PreviousState) {yog (child2ButtonState == HIGH) // Nias lub khawm {child2Strike ++; Serial.println (Txoj hlua ("Menyuam 2 muaj:") + child2Strike + "ntaus");

yog (child2Strike> = 3)

{Serial.println ("Menyuam 2 Yog Hauv Qab!"); } ncua (3000); }}

yog (child3ButtonState! = child3PreviousState)

{yog (child3ButtonState == HIGH) // Nias lub khawm {child3Strike ++; Serial.println (Txoj hlua ("Menyuam 3 muaj:") + child3Strike + "ntaus");

yog (child3Strike> = 3)

{Serial.println ("Menyuam 3 Yog Hauv Qab!"); } ncua (3000); }}

yog (child4ButtonState! = child4PreviousState)

{yog (child4ButtonState == HIGH) // Nias lub khawm {child4Strike ++; Serial.println (Txoj hlua ("Menyuam 4 muaj:") + child4Strike + "ntaus");

yog (child4Strike> = 3)

{Serial.println ("Tus Me Nyuam 4 Yog Qhov Tseeb!"); } ncua (3000); }}}

Kauj Ruam 4: Ntxiv Buzzer

Ntxiv Buzzer
Ntxiv Buzzer
Ntxiv Buzzer
Ntxiv Buzzer

Tam sim no cia ua kom ntseeg tau tias koj cov menyuam paub tias lawv yog cov hauv paus. Cia ntxiv lub suab nrov. Txhawm rau txuas lub buzzer, ua raws cov kauj ruam yooj yim no.

  1. Ntxiv Buzzer rau koj lub khob cij, npaj rau qhov chaw txij li lub vijtsam LCD tab tom los.
  2. Txuas sab Postive (lub suab nrov yuav tsum muaj + ntawm sab tom qab) rau tus Pin uas koj xaiv. Kuv ua 9.
  3. Txuas lwm sab mus rau txoj kev tsheb nqaj hlau hauv av ntawm koj lub khob cij.

Tom ntej no, hloov kho koj cov cai kom teeb tsa lub suab nrov thaum tus menyuam pib ua haujlwm. Muaj ob peb txoj hauv kev sib txawv rau tus lej rau koj lub suab nrov tab sis kuv nyiam lub suab nrov (buzzerName, hertz, ntev) rau nws qhov yooj yim Yog li piv txwv ntawm qhov no yuav yog suab nrov (buzzer, 4000, 300).

int child1ButtonPin = 13; // Qhov no yog tus pin peb lub laub khawm txuas nrog rau tus menyuam childButtonPin = 12; int child3ButtonPin = 11; int tus menyuam 4ButtonPin = 10; int child1ButtonState = 0; // Nyeem lub pob lub xeev (rau/tawm) int child2ButtonState = 0; int child3ButtonState = 0; int child4ButtonState = 0; int child1PreviousState = 0; int tus menyuam 2PreviousState = 0; int child3PreviousState = 0; int tus menyuam 4PreviousState = 0; int child1Strike = 0; int tus menyuam 2Strike = 0; int child3Strike = 0; int tus menyuam 4Strike = 0; const int buzzer = 2;

// teeb tsa muaj nuj nqi ua haujlwm ib zaug thaum koj nias rov pib dua lossis ua haujlwm rau lub rooj tsavxwm

teeb tsa tsis muaj dab tsi () {Serial.begin (9600); pinMode (child1ButtonPin, INPUT); pinMode (child2ButtonPin, INPUT); pinMode (child3ButtonPin, INPUT); pinMode (child4ButtonPin, INPUT); tus pinMode (buzzer, OUTPUT); } // lub voj kev ua haujlwm dhau mus thiab ntau dua ib txhis tsis muaj dab tsi voj () {// nyeem lub pob lub xeev (rau lossis tawm) child1ButtonState = digitalRead (child1ButtonPin);

child2ButtonState = digitalRead (child2ButtonPin);

child3ButtonState = digitalRead (child3ButtonPin);

child4ButtonState = digitalRead (child4ButtonPin);

yog (child1ButtonState! = child1PreviousState)

{yog (child1ButtonState == HIGH) // Nias lub khawm {child1Strike ++; Serial.println (Txoj hlua ("Menyuam 1 Muaj:") + child1Strike + "ntaus");

yog (child1Strike> = 3)

{Serial.println ("Tus Me Nyuam 1 Yog Hauv Qab!"); suab (buzzer, 5000, 500); // Xa lub suab 5 hertz rau 5 milliseconds

}

ncua (3000); }} yog (child2ButtonState! = child2PreviousState) {yog (child2ButtonState == HIGH) // Nias lub khawm {child2Strike ++; Serial.println (Txoj hlua ("Menyuam 2 muaj:") + child2Strike + "ntaus");

yog (child2Strike> = 3)

{Serial.println ("Menyuam 2 Yog Hauv Qab!"); suab (buzzer, 5000, 500); } ncua (3000); }}

yog (child3ButtonState! = child3PreviousState)

{yog (child3ButtonState == HIGH) // Nias lub khawm {child3Strike ++; Serial.println (Txoj hlua ("Menyuam 3 muaj:") + child3Strike + "ntaus");

yog (child3Strike> = 3)

{Serial.println ("Menyuam 3 Yog Hauv Qab!"); suab (buzzer, 5000, 500); } ncua (3000); }}

yog (child4ButtonState! = child4PreviousState)

{yog (child4ButtonState == HIGH) // Nias lub khawm {child4Strike ++; Serial.println (Txoj hlua ("Menyuam 4 muaj:") + child4Strike + "ntaus");

yog (child4Strike> = 3)

{Serial.println ("Tus Me Nyuam 4 Yog Qhov Tseeb!"); suab (buzzer, 5000, 500); } ncua (3000); }}}

Kauj Ruam 5: Ntxiv LCD Screen

Image
Image
Ntxiv ib qho LCD Screen
Ntxiv ib qho LCD Screen

Tam sim no cia lub vijtsam LCD kom pom meej thiab nyeem tau yooj yim.

  1. Ua ntej, ntxiv lub zog ntsuas rau koj lub khob cij los tswj lub vijtsam lcd. Ceev faj ntawm qhov chaw koj tso vim tias tej zaum koj yuav tsis muaj chaw nyob tam sim no.
  2. Siv sab xub ntiag txuas rau koj lub hwj chim ntsuas hluav taws xob
  3. Siv sab xis sab xis txhawm rau tsoo koj lub hwj chim.
  4. Sab nraub qaum yuav txuas nrog lub lcd screen.
  5. Ntxiv lub vijtsam LCD rau koj lub khob cij
  6. Av hauv av thawj tus pin pin rau txoj kev tsheb nqaj hlau
  7. Hlau tus pin thib ob rau lub tsheb ciav hlau.
  8. Thib peb tus pin LCD mus rau Pin 8 ntawm Arduino
  9. Plaub tus pin LCD mus rau Pin 7 ntawm Arduino
  10. Thib tsib mus rau Pin 6 ntawm Arduino
  11. Sixth Pin mus rau tus pin 5 ntawm Arduino
  12. Pins 7 txog 10 ntawm lub vijtsam LCD yog khoob
  13. Pin 11 mus rau Pin 5 ntawm Arduino
  14. Pin 12 mus rau txoj kev tsheb ciav hlau
  15. Pin 13 mus rau Pin 4 ntawm Arduino
  16. Tus Pin 14 mus rau tom qab ntawm lub hwj chim
  17. Tus Pin 15 mus rau lub tsheb ciav hlau
  18. Tus Pin 16 mus rau hauv av Rail.

Tam sim no koj yuav tau hloov kho koj cov cai kom siv lub lcd screen. Rau qhov ntawd koj yuav siv cov libary Liquid Crystal. Ceev faj ntawm koj cov ntawv sau lcd. Nco ntsoov tshem lub vijtsam thaum koj xav tau xov xwm tshiab. Tseem nco ntsoov teeb tus cursor thaum koj xav siv ob kab.

#suav nrog

LiquidCrystal lcd (3, 4, 5, 6, 7, 8); // Teeb LCD Screen

int child1ButtonPin = 13; // Qhov no yog tus pin peb lub laub khawm txuas nrog rau int child2ButtonPin = 12; int child3ButtonPin = 11; int tus menyuam 4ButtonPin = 10; int child1ButtonState = 0; // Nyeem lub pob lub xeev (rau/tawm) int child2ButtonState = 0; int child3ButtonState = 0; int child4ButtonState = 0; int child1PreviousState = 0; // Lub xeev dhau los ntawm lub khawm nias int child2PreviousState = 0; int child3PreviousState = 0; int tus menyuam 4PreviousState = 0; int child1Strike = 0; // Muaj pes tsawg tus Strikes tus menyuam muaj int child2Strike = 0; int child3Strike = 0; int tus menyuam 4Strike = 0; const int buzzer = 9; // Tus Buzzer

// teeb tsa muaj nuj nqi ua haujlwm ib zaug thaum koj nias rov pib dua lossis ua haujlwm rau lub rooj tsavxwm

teeb tsa tsis muaj dab tsi () {Serial.begin (9600); lcd.begin (16, 2); lcd.print ("Tus Menyuam"); lcd.setCursor (0, 1); lcd.print ("Tus cwj pwm hloov pauv"); pinMode (child1ButtonPin, INPUT); pinMode (child2ButtonPin, INPUT); pinMode (child3ButtonPin, INPUT); pinMode (child4ButtonPin, INPUT); tus pinMode (buzzer, OUTPUT); } // lub voj kev ua haujlwm dhau mus thiab dhau mus tas li tsis muaj dab tsi voj () {lcd.setCursor (0, 0); // nyeem khawm lub xeev (qhib lossis kaw) child1ButtonState = digitalRead (child1ButtonPin);

child2ButtonState = digitalRead (child2ButtonPin);

child3ButtonState = digitalRead (child3ButtonPin);

child4ButtonState = digitalRead (child4ButtonPin);

yog (child1ButtonState! = child1PreviousState)

{yog (child1ButtonState == HIGH) // Nias lub khawm {lcd.clear (); child1Strike ++; Serial.println (Txoj hlua ("Menyuam 1 Muaj:") + child1Strike + "ntaus"); lcd.print ("Menyuam 1 Muaj:"); lcd.setCursor (0, 1); lcd.print (child1Strike); lcd.print ("Ntaus!");

yog (child1Strike> = 3)

{Serial.println ("Tus Me Nyuam 1 Yog Hauv Qab!"); lcd.clear (); lcd.setCursor (0, 0); lcd.print ("Menyuam 1 yog"); lcd.setCursor (0, 1); lcd.print ("Hauv av!");

suab (buzzer, 5000, 500); // Xa lub suab 5 hertz rau 5 milliseconds

}

ncua (3000); }} yog (child2ButtonState! = child2PreviousState) {lcd.clear (); yog (child2ButtonState == HIGH) // Nias lub pob {child2Strike ++; Serial.println (Txoj hlua ("Menyuam 2 muaj:") + child2Strike + "ntaus"); lcd.print ("Menyuam 2 Muaj:"); lcd.setCursor (0, 1); lcd.print (child2Strike); lcd.print ("Ntaus!"); yog tias (child2Strike> = 3) {Serial.println ("Menyuam 2 Yog Hauv Qab!"); lcd.clear (); lcd.setCursor (0, 0); lcd.print ("Menyuam 2 yog"); lcd.setCursor (0, 1); lcd.print ("Hauv av!"); suab (buzzer, 5000, 500); } ncua (3000); }}

yog (child3ButtonState! = child3PreviousState)

{lcd.clear (); yog (child3ButtonState == HIGH) // Nias lub pob {child3Strike ++; Serial.println (Txoj hlua ("Menyuam 3 muaj:") + child3Strike + "ntaus"); lcd.print ("Menyuam 3 Muaj:"); lcd.setCursor (0, 1); lcd.print (child3Strike); lcd.print ("Ntaus!"); yog (child3Strike> = 3) {Serial.println ("Menyuam 3 Puas Yog Qhov Chaw!"); lcd.clear (); lcd.setCursor (0, 0); lcd.print ("Menyuam 3 yog"); lcd.setCursor (0, 1); lcd.print ("Hauv av!"); suab (buzzer, 5000, 500); } ncua (3000); }}

yog (child4ButtonState! = child4PreviousState)

{lcd.clear (); yog (child4ButtonState == HIGH) // Nias lub pob {child4Strike ++; Serial.println (Txoj hlua ("Menyuam 4 muaj:") + child4Strike + "ntaus"); lcd.print ("Menyuam 4 Muaj:"); lcd.setCursor (0, 1); lcd.print (child4Strike); lcd.print ("Ntaus!");

yog (child4Strike> = 3)

{Serial.println ("Tus Me Nyuam 4 Yog Qhov Tseeb!"); lcd.clear (); lcd.setCursor (0, 0); lcd.print ("Menyuam 4 yog"); lcd.setCursor (0, 1); lcd.print ("Hauv av!"); suab (buzzer, 5000, 500); } ncua (3000); }}} Thiab qhov ntawd, yog txhua yam koj xav tau los tsim koj tus kheej Tus Cwj Pwm Tus Cwj Pwm Hloov Kho

Pom zoo: