const int buttonPin1 = 34; // Replace D7 with the actual pin you connect the button to
const int buttonPin2 = 35; // Replace D6 with the actual pin you connect the button to
const int buttonPinplaypause = 32; // Replace D5 with the actual pin you connect the button to
const int BUZZER_PIN = 18; // Replace D1 with the actual pin you connect the buzzer to
bool musicState = false;
int currenttoneindex = 0;
int tones[3] = {1000, 2000, 3000};
int button1State = 0;
int button2State = 0;
int button3State = 0;
void setup() {
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPinplaypause, INPUT);
}
void loop(){
int newButton1State = digitalRead(buttonPin1);
int newButton2State = digitalRead(buttonPin2);
int newButton3State = digitalRead(buttonPinplaypause);
if (newButton1State == HIGH && button1State == LOW) {
// Button 1 logic - Increase tone
tone(BUZZER_PIN, tones[currenttoneindex]);
currenttoneindex = (currenttoneindex + 1) % (sizeof(tones) / sizeof(tones[0]));
delay(1000); // Adjust delay as needed
noTone(BUZZER_PIN);
}
if (newButton2State == HIGH && button2State == LOW) {
// Button 2 logic - Play a sequence
for (int i = 0; i < 2; ++i) {
tone(BUZZER_PIN, 1500);
usleep(200000);
noTone(BUZZER_PIN);
usleep(100000);
tone(BUZZER_PIN, 2000);
usleep(200000);
noTone(BUZZER_PIN);
usleep(100000);
}
}
if (newButton3State == HIGH && button3State == LOW) {
// Button 3 logic - Decrease tone
tone(BUZZER_PIN, tones[currenttoneindex]);
currenttoneindex = (currenttoneindex - 1 + sizeof(tones) / sizeof(tones[0])) % (sizeof(tones) / sizeof(tones[0]));
delay(1000); // Adjust delay as needed
noTone(BUZZER_PIN);
}
// Update button states for the next iteration
button1State = newButton1State;
button2State = newButton2State;
button3State = newButton3State;
}