Cov txheej txheem:

Arduino Piano Nrog Laub Khawm Hloov: 3 Kauj Ruam
Arduino Piano Nrog Laub Khawm Hloov: 3 Kauj Ruam

Video: Arduino Piano Nrog Laub Khawm Hloov: 3 Kauj Ruam

Video: Arduino Piano Nrog Laub Khawm Hloov: 3 Kauj Ruam
Video: Yasmi - Txiv Nraug Ntsuag ft. JN Vang (Music Video) 2024, Hlis ntuj nqeg
Anonim
Arduino Piano Nrog Laub Khawm Hloov
Arduino Piano Nrog Laub Khawm Hloov
Arduino Piano Nrog Laub Khawm Hloov
Arduino Piano Nrog Laub Khawm Hloov

Tsim los ntawm: Haotian Ye

Txheej txheem cej luam

Nov yog lub rooj ntaus piano uas muaj yim lub khawm khawm hloov uas tso cai rau koj ua si ib lub octave (Do Re Mi Fa So La Si Do) thiab nrog rau ib lub octave koj tuaj yeem sim ua qee zaj nkauj uas koj nyiam. Rau txoj haujlwm no muaj qee qhov kev paub tseem ceeb uas koj yuav tsum paub ua ntej koj pib.

Ua ntej, peb yuav tsum paub cov zaus ntawm cov ntawv sau yooj yim ntawm piano.

Cov zaus tau teev tseg hauv qab no:

Ua - 261Hz

Rov - 294Hz

Kuv - 329Hz

Zaus - 349Hz

Yog li - 392Hz

Ua hauj lwm zaus - 440Hz

Si - 493 Hz

Ua - 523Hz

Qhov thib ob, Kuv yuav qhia koj yuav ua li cas tsim lub Circuit Court los ntawm kev siv cov khoom uas tuaj yeem yuav los ntawm Lee's Electronic Store. Thaum kawg , Kuv yuav nthuav qhia thiab piav qhia cov cai uas yuav tsum tau muab xa mus rau Arduino pawg thawj coj.

Yam Koj Yuav Tsum Tau:

Arduino Uno R3 (Khoom ID: 10997)

USB A rau B Cable M/M (Khoom ID: 29861)

10K Resistor * 8 (Khoom ID: 91516)

Txawv Xim ntawm Tack Hloov * 8 (Khoom ID: 3124, 31242, 31243, 31245, 31246)

Mini Hais Lus (Khoom ID: 41680)

Breadboard (Khoom ID: 106861)

Jumper Wires (Khoom ID: 21801)

Kauj Ruam 1: Kauj Ruam 1: Txhim Kho Circuit

Kauj Ruam 1: Tsim Circuit Court
Kauj Ruam 1: Tsim Circuit Court
Kauj Ruam 1: Tsim Circuit Court
Kauj Ruam 1: Tsim Circuit Court
Kauj Ruam 1: Tsim Circuit Court
Kauj Ruam 1: Tsim Circuit Court
Kauj Ruam 1: Tsim Circuit Court
Kauj Ruam 1: Tsim Circuit Court

Ua ntej tshaj, ntxig rau txhua lub laub khawm hloov thiab hais lus me me ntawm lub khob cij ib ntawm ib qho thiab phim lawv ntawm ib kab. Tom qab ntawd txuas cov pins ntawm txhua lub laub khawm hloov mus rau hauv av. Thib ob txuas 10k resistors ntawm lub zog zoo thiab lwm tus pin ntawm txhua lub laub khawm hloov. Thiab, txuas kab ntawv no rau pins 2-9 ntawm Arduino Board. Tsis tas li, txuas hauv av rau tus pin hauv av thiab lub zog zoo rau 3.3v tus pin ntawm Arduino. Thaum kawg, txuas tus hais lus mini rau tus pin 10 ntawm Arduino.

Kauj Ruam 2: Kauj Ruam 2: Code thiab Piav Qhia

Cov cai hauv qab no yog qhov kuv tau sau

const int dub = 2;

const int dawb = 3;

const int liab = 4;

const int ntsuab = 5;

const int xiav = 6;

const int dub2 = 7;

const int ntsuab2 = 8;

const int liab2 = 9;

const tus neeg hais lus = 10; // Txuas txhua lub laub khawm hloov thiab hais lus nrog arduino lub teeb liab pins

int zaus = {262, 294, 330, 349, 392, 440, 493, 523}; // array muaj txhua zaus ntawm ib lub octave

void teeb tsa () {

// muab koj cov cai teeb tsa ntawm no, kom khiav ib zaug:

pinMode (dub, INPUT);

pinMode (dawb, INPUT);

pinMode (liab, INPUT);

pinMode (ntsuab, INPUT);

pinMode (xiav, INPUT);

pinMode (dub2, INPUT);

pinMode (ntsuab2, INPUT);

pinMode (liab2, INPUT);

pinMode (tus hais lus, NTAWV);

suab (hais lus, 2000);

Serial.begin (9600);

}

void voj () {

// muab koj cov cai tseem ceeb ntawm no, kom rov ua dua:

yog tias (digitalRead (dub) == LOW) // thaum koj nias qhov "DO" laub khawm hloov

{lub suab (tus hais lus, zaus [0], 50);

ncua (50);

noTone (hais lus);}

lwm tus yog (digitalRead (dawb) == LOW) // thaum koj nias "RE" laub khawm hloov

{lub suab (tus hais lus, zaus [1], 50);

ncua (50);

noTone (hais lus);}

lwm tus yog (digitalRead (liab) == LOW) // thaum koj nias "MI" laub khawm hloov

{suab nrov (hais lus, zaus [2], 50));

ncua (50);

noTone (hais lus);}

lwm tus yog (digitalRead (ntsuab) == LOW) // thaum koj nias "FA" laub khawm hloov

{lub suab (tus hais lus, zaus [3], 50);

ncua (50);

noTone (hais lus);}

lwm tus yog (digitalRead (xiav) == LOW) // thaum koj nias "SO" laub khawm hloov

{lub suab (tus hais lus, zaus [4], 50);

ncua (50);

noTone (hais lus);}

lwm tus yog (digitalRead (black2) == LOW) // thaum koj nias "LA" laub khawm hloov

{lub suab (tus hais lus, zaus [5], 50);

ncua (50);

noTone (hais lus);}

lwm tus yog (digitalRead (ntsuab2) == LOW) // thaum koj nias "SI" laub khawm hloov

{lub suab (tus hais lus, zaus [6], 50);

ncua (50);

noTone (hais lus);}

lwm tus yog (digitalRead (red2) == LOW) // thaum koj nias qhov "DO" laub khawm hloov

{suab nrov (hais lus, zaus [7], 50));

ncua (50);

noTone (hais lus);}

lwm // thaum koj nias tsis muaj dab tsi

noTone (hais lus);

}

Ua ntej tshaj, peb yuav tsum tshaj tawm txhua lub laub khawm hloov pauv thiab hais lus raws tus pin ntawm 2 txog 10 ntawm Arduino. Txhua qhov hloov pauv sawv cev rau ib daim ntawv. Tom qab ntawd, siv ib qho kab los tso tag nrho cov zaus hauv. Tom ntej no, Yog thiab lwm nqe lus yog qhov kuv siv qhia rau Arduino paub qhov twg khawm hloov pauv kuv nias.

Thaum kawg, txuas koj Arduino board rau koj lub khoos phis tawj lossis laptop nrog usb A rau B cable. Ua ntej koj xa koj cov cai, koj tseem yuav tsum rub tawm software Arduino thiab ua qee qhov teeb tsa ua ntej. Xaiv Cov Cuab Yeej -> Pawg Thawj Coj -> Arduino/Genuino Uno; Tom qab ntawd peb yuav tsum xaiv qhov chaw sib txuas lus txuas nrog Arduino board. Xaiv Cov Cuab Yeej -> Chaw nres nkoj, tom qab ntawv qhov twg los xij lub npe hu ua "(Arduino/Genuino Uno)." Tom qab ntawd, koj tuaj yeem xa cov cai rau Arduino board.

Pom zoo: