I'm following one of the tutorials on the Arduino website (https://www.arduino.cc/en/Tutorial/toneKeyboard)
So, I'm trying to make a program where when I press one of the 3 buttons, it outputs a different sound through the tone function out to the speaker.
and because I don't have any force sensing resistors I used 3 push buttons instead. I changed the code up a little but it won't seem to work.
And i connected a 220 resistor to the speaker.
Please help me! I can't find the problem!
//i included a library for this
#include "pitches.h"
const int threshold = 10;
int notes[] = {
NOTE_A4, NOTE_B4, NOTE_C3
};
void setup() {
// put your setup code here, to run once:
// digital pins 2,3,4 are connected to a push button each
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
//pin 8 is connected to the speaker
pinMode(8,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
for(int thisButton = 0; thisButton < 3; thisButton++) {
//i did thisButton+2 because the pins are 2,3,4 not 0,1,2
int buttonReading = digitalRead(thisButton+2);
if (buttonReading < threshold) {
tone(8, notes[thisButton], 20);
}
}
}
I'm following one of the tutorials on the Arduino website (https://www.arduino.cc/en/Tutorial/toneKeyboard)
So, I'm trying to make a program where when I press one of the 3 buttons, it outputs a different sound through the tone function out to the speaker.
and because I don't have any force sensing resistors I used 3 push buttons instead. I changed the code up a little but it won't seem to work.
And i connected a 220 resistor to the speaker.
Please help me! I can't find the problem!
+this time i added a picture of the circuit!
//i included a library for this
#include "pitches.h"
const int threshold = 10;
int notes[] = {
NOTE_A4, NOTE_B4, NOTE_C3
};
void setup() {
// put your setup code here, to run once:
// digital pins 2,3,4 are connected to a push button each
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
//pin 8 is connected to the speaker
pinMode(8,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
for(int thisButton = 0; thisButton < 3; thisButton++) {
//i did thisButton+2 because the pins are 2,3,4 not 0,1,2
int buttonReading = digitalRead(thisButton+2);
if (buttonReading < threshold) {
tone(8, notes[thisButton], 20);
}
}
Duplicate post of simple keyboard using the tone() function - Programming Questions - Arduino Forum
DON"T DO THAT!!! You waste people's time giving you help that was already provided in your other post. If you had bothered to read the answers in your original post you'd already know what the problem is. I've placed you on my personal blacklist.