helllo
im having trouble with my code.
I have 4 pushbuttons wired on digital pins 13,12,11,10
and a speaker on pin 7
i want each button to play a different tone when pressed
here is my code,
it compiles
but i get no sound
#include <Tone.h>
int switch1 = 13; //The four button input pins
int switch2 = 12;
int switch3 = 11;
int switch4 = 10;
int speakerPin = 7;
int input1 = LOW;
int input2 = LOW;
int input3 = LOW;
int input4 = LOW;
void setup() {
Serial.begin(9600);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);
pinMode(switch4, INPUT);
pinMode(speakerPin, OUTPUT);
}
void input() {
input1 = digitalRead(switch1);
input2 = digitalRead(switch2);
input3 = digitalRead(switch3);
input4 = digitalRead(switch4);
if (input1 == HIGH){
playTone(1915, 200);
delay(200);
}
if (input2 == HIGH){
playTone(1519, 200);
delay(200);
}
if (input3 == HIGH){
playTone(1275, 200);
delay(200);
}
if (input4 == HIGH){
playTone(956, 200);
delay(200);
}
}
void playTone(int tone, int duration) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
}
void loop() { //Unused void loop(), though for some reason it doesn't compile without this /shrug
}