PIANO CODE:
// הכנתי כפתורים שמדמים פסנתר כל כפתור מייצג תו
#define T_C 220 // הגדרת הרץ לכל תו (לכל תו יש מספר אחר בהרץ לקחתי את המידע מהמצגת של דני בשיעור 3)
#define T_CD 246.94
#define T_D 261.63
#define T_DE 293.66
#define T_E 329.63
#define T_F 349.23
#define T_FG 392
#define T_G 440
#define T_GA 493.88
#define T_A 587.33
#define T_B 523.25
const int C = 10; //הגדרת יציאת חשמל מאדרוינו לכפתור
const int CD = 12;
const int D = 9;
const int DE = 13;
const int E = 8;
const int F = 7;
const int FG = 3;
const int G = 6;
const int GA = 2;
const int A = 5;
const int B = 4;
const int Buzz = 11;
void setup()
{
pinMode(C, INPUT_PULLUP); //מכניס 5 וולט וכשלוחצים הוא מוציא אותו
pinMode(CD, INPUT_PULLUP);
pinMode(D, INPUT_PULLUP);
pinMode(DE, INPUT_PULLUP);
pinMode(E, INPUT_PULLUP);
pinMode(F, INPUT_PULLUP);
pinMode(FG, INPUT_PULLUP);
pinMode(G, INPUT_PULLUP);
pinMode(GA, INPUT_PULLUP);
pinMode(A, INPUT_PULLUP);
pinMode(B, INPUT_PULLUP);
}
void loop()
{
if( digitalRead(C) == LOW){ //לולאה אם לחצתי על הכתפור תשמיע צליל וחכה חצי שניה
tone(Buzz,T_C);
delay (500);
}
if(digitalRead(CD) == LOW)
{
tone(Buzz,T_CD);
delay (500);
}
if(digitalRead(D) == LOW)
{
tone(Buzz,T_D);
delay (500);
}
if(digitalRead(DE) == LOW)
{
tone(Buzz,T_DE);
delay (500);
}
if(digitalRead(E) == LOW)
{
tone(Buzz,T_E);
delay (500);
}
if(digitalRead(F) == LOW)
{
tone(Buzz,T_F);
delay (500);
}
if(digitalRead(FG) == LOW)
{
tone(Buzz,T_FG);
delay (500);
}
if(digitalRead(G) == LOW)
{
tone(Buzz,T_G);
delay (500);
}
if(digitalRead(GA) == LOW)
{
tone(Buzz,T_GA);
delay (500);
}
if(digitalRead(A) == LOW)
{
tone(Buzz,T_A);
delay (500);
}
if(digitalRead(B) == LOW)
{
tone(Buzz,T_B);
delay (500);
}
noTone(Buzz); //עצור השמעת צליל
}
