This program puts out continuous tone without the switches
removed switches
/*
Keyboard
Plays a pitch that changes based on a changing analog input
circuit:
- three force-sensing resistors from +5V to analog in 0 through 5
- three 10 kilohm resistors from analog in 0 through 5 to ground
- 8 ohm speaker on digital pin 8
created 21 Jan 2010
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneKeyboard
*/
#include "pitches.h"
const int threshold = 10; // minimum reading of the sensors that generates a note
// notes to play, corresponding to the 3 sensors:
int notes[] = {
NOTE_A4, NOTE_B4, NOTE_C3
};
void setup() {
}
void loop() {
for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
// get a sensor reading:
int sensorReading = analogRead(thisSensor);
// if the sensor is pressed hard enough:
if (sensorReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[thisSensor], 2);
}
}
}
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
Hi Guys
This my first time I'm trying to learn Arduino language. I know nothing except that I tried the blink example. The only way is to use opensource code and try to modify it.(I have VB experience.
Please don't ban me.
The question is how to stop playing a tune on this program because when I upload it it starts to play a key.
I removed all the switches but tone is still there.
I have taken out the "tone(8, notes[thisSensor], 2);" for testing purposes and down load it again and of course no tone starts to play.
I thought that the noise was coming the computer over the USB cable. Took it off and replace it with 5V battery.. No joy.
I also seen that thisSensor the value if no key is pressed that it is 0. I tried to replace this value with 1 because i have read that if the tone value is 0 it will be continuous tone. But It is not the sensor value that causes the problem.
Is there any body that can help me to stop the continuous tone when loaded.
I know that it is not my own work but it is in the public domain. So presume I can use it and modify it.
This is my way of learning.
I have 3 10K resistors connected to the micro switches in series with A0-A3
the other side +3V. I've checked with the scope and the stay low until switch is pushed then turn to High
JML
Looking at the circuit it seems I have a wiring problem now that I transfer everting thing to the breadboard. Fixed my wiring problem
Every thing wiring ok. Stil get that continuous tone