Cov txheej txheem:

Arduino Piano: 3 Kauj Ruam
Arduino Piano: 3 Kauj Ruam

Video: Arduino Piano: 3 Kauj Ruam

Video: Arduino Piano: 3 Kauj Ruam
Video: Top 10 best arduino music projects 2024, Kaum ib hlis
Anonim
Arduino Piano
Arduino Piano

Qhov "Piano" no tuaj yeem ua suab paj nruag octave ntawm piano tiag. Kev nias cov nyees khawm yuav sawv cev rau qhov nias tus yuam sij ntawm lub piano. Lub suab yuav raug xa mus los ntawm tus neeg hais lus Piezo.

Kauj ruam 1: Cov ntaub ntawv

1. Arduino Uno

2. USB xaim

3. 3 daim ntawv qhia zaub mov

4.8 Pushbuttons

5. 8 100 Ohm resistors

6. "Piezo" Tus Hais Lus

7. Ntau Tus Txiv Neej Hluav Taws Xob (Txog 20)

8. Soldering Hlau

Kauj ruam 2: Tsim Kev Teeb

Tsim Kev Teeb
Tsim Kev Teeb

Tsim 8 cov nyees khawm nrog txhua tus mus rau 8 tus pin sib txawv hauv Arduino, ntxiv tus tiv thaiv rau txhua tus, thiab txuas lawv rau hauv av (siv Txiv neej cov xov hlau).

Txuas tus neeg hais lus rau tus pin Arduino, thiab lwm sab rau hauv av. Koj yuav tsum tau xaim cov xov hlau rau tus hais lus kom nws tsis poob tawm. Nco ntsoov tias ob lub xov hlau uas tau muab muag rau tus hais lus tsis txhob kov ib leeg.

Kauj Ruam 3: Tsim Txoj Cai

#define NOTE_B0 31 #txhais NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTA NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 #d efine NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #defineE_8 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOT20DEE_76 txhais NOTE_D7 2349 #define NOTE_DS7 2489 #fine NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 4699 #Txhais NOTE_DS8 4978

Cov "#defines" no yog qhia rau tus neeg hais lus uas zaus ua rau qhov twg

cov int C = 2; cov int D = 3; cov int E = 4; cov int F = 5; const int G = 6; cov int A = 7; const int B = 8; const int C2 = 9; const int piezoPin = 10; int cState = 0; int dState = 0; int eState = 0; int fState = 0; int gState = 0; int aState = 0; int bState = 0; int c2State = 0;

Xaiv Arduino tus pin rau cov nyees khawm. "cState, dState, eState, thiab lwm yam;" yog cov hloov pauv uas txuag seb lub khawm raug nias. A 0 txhais tau tias nws tsis raug nias, a 1 txhais tau tias nws raug nias.

teeb tsa tsis muaj dab tsi () {// muab koj cov cai teeb tsa ntawm no, kom khiav ib zaug: pinMode (10, OUTPUT); Serial.begin (9600); }

void loop () {// muab koj tus lej tseem ceeb ntawm no, kom rov ua dua: cState = digitalRead (C); dState = digitalRead (D); eState = digitalRead (E); fState = digitalRead (F); gState = digitalRead (G); aState = digitalRead (A); bState = digitalRead (B); c2State = digitalRead (C2);

Lub xeev ntawm lub pob (yog tias nws tau nyem lossis tsis) raug cawm hauv "cState, dState, eState, thiab lwm yam;"

A 0 txhais tau tias nws tsis raug nias, a 1 txhais tau tias nws raug nias.

yog (cState == 1) {tone (piezoPin, 131); } lwm {noTone (piezoPin);} yog (dState == 1) {suab (piezoPin, 147); } lwm {noTone (piezoPin);} yog (eState == 1) {suab (piezoPin, 165); } lwm {noTone (piezoPin);} yog (fState == 1) {suab (piezoPin, 175); } lwm {noTone (piezoPin);} yog (gState == 1) {laus (piezoPin, 196); } lwm {noTone (piezoPin);} yog (aState == 1) {suab (piezoPin, 220); } lwm {noTone (piezoPin);} yog (bState == 1) {laus (piezoPin, 247); } lwm {noTone (piezoPin);} yog (c2State == 1) {suab (piezoPin, 262); } lwm {noTone (piezoPin);}

Yog tias lub pob nyem, nws qhia cov servo los ua cov ntawv pov thawj zaus (ceeb toom). Txoj haujlwm

{noTone (piezoPin);} qhia lawv tias yog tias lub pob tsis raug nias kom tsis ua dab tsi. Yog li thaum twg lub pob nyem, nws yuav ua nws daim ntawv teev tseg.

Pom zoo: