Home > other >  For help, the arduino program, to help
For help, the arduino program, to help

Time:09-24

Online to find a can control buzzer playing music I'd like to add a code with a button control according to start playing music again don't know how to change the program
Program the following

Int PIN_SPEAKER=4;

Int length=25;

Char notes []="ggagCbggagDCggGECbaffECDC";

,1,2,2,2,4 int beats []={1, 1,1,2,2,2,4, 1,1,2,2,2,2,2, 1,1,2,2,2,4,1};

Int tempo=300;

Void playTone (int tone, int duration) {

For (long I=0; I & lt; Duration * 1000 l; I +=tone * 2) {

DigitalWrite (PIN_SPEAKER, HIGH);

DelayMicroseconds (tone);

DigitalWrite (PIN_SPEAKER, LOW);

DelayMicroseconds (tone);

}

}

Void playNote (char note, int duration) {

Char names []={' c ', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g'};

Int tones []={1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 853, 759, 716, 637, 568};

for (int i=0; I & lt; 12. I++) {

If (names [I]==note) {

Serial. Print (" value: ");

Serial. Println (note);

PlayTone (tones [I] * 2, duration).

}

}

}

Void setup () {

PinMode (PIN_SPEAKER, the OUTPUT);

}

Void loop () {

for (int i=0; I & lt; Length; I++) {

If (notes [I]==' ') {

Delay (beats [I] * tempo);

} else {

[I] playNote (notes, beats [I] * tempo);

}

Delay (tempo/2);

}

}
  • Related