Hi, I'm super new with Arduino (and programming as a whole...) but I'm trying to learn
I have an Arduino Uno and I'm trying to use a three push buttons to sound three separate tones on an 8 ohm speaker. I couldn't find a tutorial to match exactly what I needed so I pulled from a bunch of them to get kind of close ( I thought). But when I ran the sketch with the board I just get a bunch of noise and a slightly different tone when I press the middle button. This is what I have so far for my sketch, it looks right to me but I know it's way off and I would like some help. (In case anyone is curious I'm trying to make it so I can use the button's to play Harmonica's theme from Once Upon a Time in the West)
#include "pitches.h"
int speakerPin = 8;
int buttonPins[] = {
0, 1, 2
};
int notes[] = {
NOTE_C5, NOTE_DS5, NOTE_E5
};
int buttonState = 0;
void setup() {
pinMode(buttonPins, INPUT);
}
void loop() {
for (int buttonPins = 0; buttonPins < 3; buttonPins++) {
int buttonState = digitalRead(buttonPins);
if (buttonState == HIGH) {
tone(8, notes[buttonPins], 20);
}
else{
noTone(8);
}
}
}