/*
Arduino | general-help
t-72b3m — 6/15/24 at 12:36 PM
i need some help with a projject for father day
i would like it if someone helped me because i am just
now getting back into coding and im not the best
See https://docs.arduino.cc/built-in-examples/digital/toneMelody/
*/
// pin constants
const int BTN_1_PIN = 11;
const int BTN_2_PIN = 10;
const int BTN_3_PIN = 9;
const int BTN_4_PIN = 8;
const int PEIZO_PIN = 2;
// variables will change:
int buttonState1; // variable for reading the pushbutton status
int buttonState2;
int buttonState3;
int buttonState4;
void setup() {
pinMode(PEIZO_PIN, OUTPUT);
pinMode(BTN_1_PIN, INPUT_PULLUP);
pinMode(BTN_2_PIN, INPUT_PULLUP);
pinMode(BTN_3_PIN, INPUT_PULLUP);
pinMode(BTN_4_PIN, INPUT_PULLUP);
}
void loop() {
// read the state of the pushbuttons
buttonState1 = digitalRead(BTN_1_PIN);
buttonState2 = digitalRead(BTN_2_PIN);
buttonState3 = digitalRead(BTN_3_PIN);
buttonState4 = digitalRead(BTN_4_PIN);
if (buttonState1 == LOW) {
tone(PEIZO_PIN, 110);
} else {
noTone(PEIZO_PIN);
}
if (buttonState2 == LOW) {
tone(PEIZO_PIN, 220);
} else {
noTone(PEIZO_PIN);
}
if (buttonState3 == LOW) {
tone(PEIZO_PIN, 440);
} else {
noTone(PEIZO_PIN);
}
if (buttonState4 == LOW) {
tone(PEIZO_PIN, 880);
} else {
noTone(PEIZO_PIN);
}
}