Я пытаюсь собрать счетчик нажатий кнопок с моим устройством аргона. У меня есть пара звуков, которые я хочу чередовать, но не могу заставить счетчик работать, чтобы я сменил песни A и B. Я хотел установить песню A в качестве встречных четностей и песню B в противоположных коэффициентах. У меня сейчас очень мало и я не знаю, куда go откуда я. Не уверен, как загрузить то, что у меня есть в настоящее время.
int button = A0;
int buzzer = A2;
// Defining Sound
int sound1[] = {1700,2500,2800,2000,2500,1500,2000,1800};
int sound2[] = {3800,3600,3400,3200,2400,2600,2800,3000};
//Defining Duration Of Notes
int Duration1[] = {4,2,4,2,4,2,4,2};
int Duration2[] = {2,4,2,4,2,2,4,2};
//Setting Button Count
int bcount = 0;
#define MAX 2
//Creates The Setup Of Code
void setup()
{
//Creates The Input Of Button Being Pressed
pinMode (button, INPUT);
//Creates The Output Of The Buzzer
pinMode (buzzer, OUTPUT);
}
void loop() {
//When Button Is Pressed
if (digitalRead(button) == 1) {
bcount = bcount + 1;
}
else if
(bcount = 0);
for (int i = 0; i < bcount; i++) {
digitalWrite(buzzer, 1);
if (bcount == MAX) {
bcount = 0;
break;
}
//Reads Notes
for (int Note = 0; Note < 8; Note++){
//Note Duration
int Duration = 1000/Duration1[Note];
//Sends Notes To Speaker
tone(buzzer, sound1[Note], Duration);
//Sets Delay Between Notes
int pauseBetweenNotes = Duration * 1.50;
//Delay Itself
delay(pauseBetweenNotes);
//Stop To The Sound
noTone(buzzer);
}
}
//When Button Is Pressed 2nd Time
if(digitalRead(button) == 2) {
//Reads Notes
for (int Note = 0; Note < 8; Note++){
//Note Duration
int Duration = 1000/Duration2[Note];
//Sends Notes To Speaker
tone(buzzer, sound2[Note], Duration);
//Sets Delay Between Notes
int pauseBetweenNotes = Duration * 1.50;
//Delay Itself
delay(pauseBetweenNotes);
//Stop To The Sound
noTone(buzzer);
}
}
}