Keyboard open source program

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);
 
    }
     
    
  }
}

Your other topic on the same subject deleted.

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.

Thank you.

is there a question?

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.

it's called C++ and Arduino added APIs to make hardware access easier for everyone and a handful ancillary functions / macros.

what's connected to A0 A1 and A2 ?

I have 3 micro switches. While I was testing with oscilloscope. I found that if I put the positive on A0 the tone stops and working fine.

if you don't have a pullup or pulldown resistor connected to the switches, then you have an antenna and the reading will just be "garbage"

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

How would I put a pull down resistor ?

image

there are tons of examples and explanations on line - see Using Pushbuttons with Arduino. Pullup vs Pulldown resistors - Hackster.io (first google hit with an image)

will Check the circuit but I've better go now I must wash the dishes and house cleaning before wife comes. I'll post tomorrow

It's important to manage priorities !

1 Like

Morning JML
I did not do the pull down yet I noticed is that with no switches connected the tone is still there. Does that make sense?

I have changed the Nano , the break out module .Running on batt and breadboard

Yes the code still reads the pin states

Sorry to reply so late we had load shedding.
I'm going to pul all the pins low and let you know

JML
Looking at the circuit it seems I have a wiring problem now that I transfer everting thig to the breadboard

you could use the built in INPUT PULLUP for the switches

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

my crystal ball is in the dishwasher ...
if you want advices post

  • your code
  • a readable drawing of your circuit
  • a picture of your gig (in focus)
  • an explanation of what happens