i'm trying to make a device that takes the input of a switch and makes a set frequency. That part works, what i'm having trouble with is using two switches at once to make another frequency. I thought the else if (buttonState7 == HIGH) && (buttonState8 == HIGH) would work to make freq 8 which should make 1000 Hz . Any help would be very much appreciated also if my format for posting is in need of improvement i do apologize, i tried following the guidelines but i may have missed some things.
int freq[] = {
200,
300,
400,
500,
600,
700,
800,
900,
1000,
};
const int a = 12; //#9 on box
const int b = 11; //#4 on box
const int c = 10; //#8 on box
const int d = 9; //#5 on box
const int e = 7; //#7 on box
const int f = 6; //#3 on box
const int g = 5; //#6 on box
const int h = 4;//#1 on box
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;
int buttonState7 = 0;
int buttonState8 = 0;
void setup() {
pinMode(a, INPUT);
pinMode(b, INPUT);
pinMode(c, INPUT);
pinMode(d, INPUT);
pinMode(e, INPUT);
pinMode(f, INPUT);
pinMode(g, INPUT);
pinMode(h, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState1 = digitalRead(a);
buttonState2 = digitalRead(b);
buttonState3 = digitalRead(c);
buttonState4 = digitalRead(d);
buttonState5 = digitalRead(e);
buttonState6 = digitalRead(f);
buttonState7 = digitalRead(g);
buttonState8 = digitalRead(h);
if (buttonState1 == HIGH) {
tone(8, freq[0]);
}
else if (buttonState2 == HIGH) {
tone(8, freq[1]);
}
else if (buttonState3 == HIGH) {
tone(8, freq[2]);
}
else if (buttonState4 == HIGH) {
tone(8, freq[3]);
}
else if (buttonState5 == HIGH) {
tone(8, freq[4]);
}
else if (buttonState6 == HIGH) {
tone(8, freq[5]);
}
else if (buttonState7 == HIGH) {
tone(8, freq[6]);
}
else if (buttonState8 == HIGH) {
tone(8, freq[7]);
}
else if (buttonState7 == HIGH) && (buttonState8 == HIGH) {
tone(8, freq[8]);
}
else{
noTone(8);
}
}