Untitled
Anonymous
plain_text
08/14/2026 2:32 PM
1.0 KB
2
Indexable
const int buzzer = 7;
const int led = 2;
const int buton = 8;
const int NUM_NOTE = 8;
const int note[NUM_NOTE] = {262, 294, 330, 349, 392, 349, 330, 262}; // Do Re Mi Fa Sol Fa Mi Do
int pozitie = 0; // ce nota urmeaza
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
pinMode(buton, INPUT);
}
void loop() {
if (digitalRead(buton) == HIGH) {
tone(buzzer, note[pozitie], 300);
digitalWrite(led, HIGH);
delay(300);
digitalWrite(led, LOW);
pozitie++;
if (pozitie >= NUM_NOTE) {
pozitie = 0; // am ajuns la ultima nota, reincepem melodia
}
// asteptam sa dea drumul la buton, ca sa nu sara mai multe note dintr-o apasare
while (digitalRead(buton) == HIGH) {
delay(50);
}
}
}Editor is loading...
Leave a Comment