Самое простое пианино, которое воспроизводит заданную мелодию:
#define DO 7 // high/low
#define RE 8 // high/low
#define MI 9 // ~
#define FA 10 // ~
#define SO 11 // ~
#define LA 12 // high/low
#define SI 13 // high/low
int pol = 1000;
int chet = 500;
void setup() {
for (int x=7; x==13; x++) {
pinMode(x, OUTPUT);
}
}
void loop() {
analogWrite(MI, 0);
digitalWrite(LA, HIGH);
delay(pol);
digitalWrite(LA, LOW);
analogWrite(FA, 255);
delay(chet);
analogWrite(FA, 0);
digitalWrite(LA, HIGH);
delay(chet);
digitalWrite(LA, LOW);
analogWrite(SO, 255);
delay(chet);
analogWrite(SO, 0);
analogWrite(FA, 255);
delay(chet);
analogWrite(FA, 0);
analogWrite(MI, 255);
delay(pol);
analogWrite(MI, 0);
digitalWrite(LA, HIGH);
delay(chet);
digitalWrite(LA, LOW);
digitalWrite(LA, HIGH);
delay(chet);
digitalWrite(LA, 0);
analogWrite(FA, 255);
delay(chet);
analogWrite(FA, 0);
digitalWrite(LA, HIGH);
delay(chet);
digitalWrite(LA, LOW);
analogWrite(SO, HIGH);
delay(chet);
analogWrite(SO, LOW);
analogWrite(FA, 255);
delay(chet);
analogWrite(FA, 0);
analogWrite(MI, 255);
delay(pol);
}
диоды - ноты от ДО до СИ
#define DO 7 // high/low
#define RE 8 // high/low
#define MI 9 // ~
#define FA 10 // ~
#define SO 11 // ~
#define LA 12 // high/low
#define SI 13 // high/low
int pol = 1000;
int chet = 500;
void setup() {
for (int x=7; x==13; x++) {
pinMode(x, OUTPUT);
}
}
void loop() {
analogWrite(MI, 0);
digitalWrite(LA, HIGH);
delay(pol);
digitalWrite(LA, LOW);
analogWrite(FA, 255);
delay(chet);
analogWrite(FA, 0);
digitalWrite(LA, HIGH);
delay(chet);
digitalWrite(LA, LOW);
analogWrite(SO, 255);
delay(chet);
analogWrite(SO, 0);
analogWrite(FA, 255);
delay(chet);
analogWrite(FA, 0);
analogWrite(MI, 255);
delay(pol);
analogWrite(MI, 0);
digitalWrite(LA, HIGH);
delay(chet);
digitalWrite(LA, LOW);
digitalWrite(LA, HIGH);
delay(chet);
digitalWrite(LA, 0);
analogWrite(FA, 255);
delay(chet);
analogWrite(FA, 0);
digitalWrite(LA, HIGH);
delay(chet);
digitalWrite(LA, LOW);
analogWrite(SO, HIGH);
delay(chet);
analogWrite(SO, LOW);
analogWrite(FA, 255);
delay(chet);
analogWrite(FA, 0);
analogWrite(MI, 255);
delay(pol);
}
Комментариев нет:
Отправить комментарий