Код: Выделить всё
int speakerPin = 10;
int songbuttonPin = 7;
int lightbuttonPin = 6;
void setup()
{
pinMode(speakerPin, OUTPUT);
pinMode(songbuttonPin, INPUT);
pinMode(lightbuttonPin, INPUT);
}
void loop()
{
if (digitalRead(songbuttonPin) == LOW) {
play('b', 6);
play('D', 3);
play('a', 6);
play('g', 1.5);
play('a', 1.5);
play('b', 6);
play('D', 3);
play('a', 8);
play('b', 6);
play('D', 3);
play('A', 6);
play('G', 3);
play('D', 6);
play('C', 1.5);
play('b', 1.5);
play('a', 6);
play('g', 1.5);
play('a', 1.5);
while (true) {}
}
void play( char note, int beats)
{
int numNotes = 14;
char notes[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B', ' '}
int frequencies[] = {131, 147, 165, 175, 196, 220, 247, 262, 294, 330, 349, 392, 440, 494, 0};
int currentFrequency = 0;
int beatLength = 150;
for (int i = 0; i < numNotes; i++)
{
if (notes[i] == note)
{
currentFrequency = frequencies[i];
}
}
tone(speakerPin, currentFrequency, beats * beatLength);
delay(beats * beatLength);
delay(50);
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... inkercad-c