TonePitchFollower with multiple speakers

Im using an arduino uno and I am trying to change the pitch of multiple speakers with the potentiometer. I am also using the potentiometer to create a waves of "o's" with in the serial monitor.

Here is my code:

/*
  Switch statement
 
 Demonstrates the use of a switch statement.  The switch
 statement allows you to choose from among a set of discrete values
 of a variable.  It's like a series of if statements.
 
 To see this sketch in action, but the board and sensor in a well-lit
 room, open the serial monitor, and and move your hand gradually
 down over the sensor.
 
 The circuit:
 * photoresistor from analog in 0 to +5V
 * 10K resistor from analog in 0 to ground
 
 created 1 Jul 2009
 modified 30 Aug 2011
 by Tom Igoe 
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/SwitchCase
 */

// these constants won't change:
const int sensorMin = 0;      // sensor minimum, discovered through experiment
const int sensorMax = 600;    // sensor maximum, discovered through experiment

void setup() {
  // initialize serial communication:
  Serial.begin(9600);  
}

void loop() {
  // read the sensor:
  int sensorReading = analogRead(A0);
  // map the sensor range to a range of four options:
  int range = map(sensorReading, sensorMin, sensorMax, 0, 58);
  
   int thisPitch = map(sensorReading, 0, 1023, 0, 500);

  // play the pitch:
  tone(8, thisPitch, 10);

  // do something different depending on the 
  // range value:
  switch (range) {
  case 0:    // your hand is on the sensor
    Serial.println("o");
    break;
  case 1:    // your hand is close to the sensor
    Serial.println("oo");
    break;
  case 2:    // your hand is a few inches from the sensor
    Serial.println("ooo");
    break;
  case 3:    // your hand is nowhere near the sensor
    Serial.println("oooo");
    break;
      case 4:    // your hand is on the sensor
    Serial.println("ooooo");
    break;
  case 5:    // your hand is close to the sensor
    Serial.println("oooooo");
    break;
  case 6:    // your hand is a few inches from the sensor
    Serial.println("ooooooo");
    break;
  case 7:    // your hand is nowhere near the sensor
    Serial.println("oooooooo");
    break;
    case 8:    // your hand is on the sensor
    Serial.println("ooooooooo");
    break;
  case 9:    // your hand is close to the sensor
    Serial.println("oooooooooo");
    break;
  case 10:    // your hand is a few inches from the sensor
    Serial.println("ooooooooooo");
    break;
  case 11:    // your hand is nowhere near the sensor
    Serial.println("oooooooooooo");
    break;
      case 12:    // your hand is on the sensor
    Serial.println("ooooooooooooo");
    break;
  case 13:    // your hand is close to the sensor
    Serial.println("oooooooooooooo");
    break;
  case 14:    // your hand is a few inches from the sensor
    Serial.println("ooooooooooooooo");
    break;
  case 15:    // your hand is nowhere near the sensor
    Serial.println("oooooooooooooooo");
    break;
     case 16:    // your hand is on the sensor
    Serial.println("ooooooooooooooooo");
    break;
  case 17:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooo");
    break;
  case 18:    // your hand is a few inches from the sensor
    Serial.println("oooooooooooooooooo");
    break;
  case 19:    // your hand is nowhere near the sensor
    Serial.println("ooooooooooooooooooo");
    break;
      case 20:    // your hand is on the sensor
    Serial.println("oooooooooooooooooooo");
    break;
  case 21:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooooooo");
    break;
  case 22:    // your hand is a few inches from the sensor
    Serial.println("oooooooooooooooooooooo");
    break;
  case 23:    // your hand is nowhere near the sensor
    Serial.println("ooooooooooooooooooooooo");
    break;
    case 24:    // your hand is on the sensor
    Serial.println("oooooooooooooooooooooooo");
    break;
  case 25:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooooooooooo");
    break;
  case 26:    // your hand is a few inches from the sensor
    Serial.println("oooooooooooooooooooooooooo");
    break;
  case 27:    // your hand is nowhere near the sensor
    Serial.println("ooooooooooooooooooooooooooo");
    break;
      case 28:    // your hand is on the sensor
    Serial.println("oooooooooooooooooooooooooooo");
    break;
  case 29:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooooooooooooooo");
    break;
  case 30:    // your hand is a few inches from the sensor
    Serial.println("oooooooooooooooooooooooooooooo");
    break;
  case 31:    // your hand is nowhere near the sensor
    Serial.println("ooooooooooooooooooooooooooooooo");
    break;
      case 32:    // your hand is on the sensor
    Serial.println("oooooooooooooooooooooooooooooooo");
    break;
  case 33:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooooooooooooooooooo");
    break;
  case 34:    // your hand is a few inches from the sensor
    Serial.println("oooooooooooooooooooooooooooooooooo");
    break;
  case 35:    // your hand is nowhere near the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooo");
    break;
      case 36:    // your hand is on the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooo");
    break;
  case 37:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooo");
    break;
  case 38:    // your hand is a few inches from the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooo");
    break;
  case 39:    // your hand is nowhere near the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooooo");
    break;
    case 40:    // your hand is on the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooooo");
    break;
  case 41:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 42:    // your hand is a few inches from the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 43:    // your hand is nowhere near the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooooooooo");
    break;
      case 44:    // your hand is on the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 45:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 46:    // your hand is a few inches from the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 47:    // your hand is nowhere near the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
     case 48:    // your hand is on the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 49:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
         case 50:    // your hand is on the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 51:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 52:    // your hand is a few inches from the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 53:    // your hand is nowhere near the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
     case 54:    // your hand is on the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 55:    // your hand is close to the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 56:    // your hand is close to the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
         case 57:    // your hand is on the sensor
    Serial.println("ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
    break;
  case 58:    // your hand is close to the sensor
    Serial.println("oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
    break;


  
  } 

}

If anyone could help me learn how to have multiple speakers pitch changed my the potentiometer that would be super cool! Thanks.

Before you run out of RAM, can I recommend you read about the "for" loop?

i just looked at this. but what will this be able to do for me?

in addition to what I said before...

If I could have multiple potentiometers control either the same speaker or different ones as well; that would be cool as well!

i just looked at this. but what will this be able to do for me?

It'll cut your code to about a tenth the length it is now.

My code is very long. But Im pretty sure I need it to be b/c when I use the serial monitor and I spin the potentiometer it will make a wave of "o's"

for instance:

o
oo
ooo
oooo
ooooo
oooooo
ooooo
oooo
ooo
oo
o
oo
oo
ooo
oooo
ooooo
oooooo
oooooo
ooooo
ooooo
oooooo
oooooo
ooooooo
ooooooo
oooooooo
oooooooo
ooooooo
oooooo
ooooo
oooo
ooo
oo
o

The o's go from 1 to 58
idk how having that on a loop will give me the same effect of the "wave" Im going for

But Im pretty sure I need it to be

No, sorry, I'm totally unconvinced

Well how would I go about applying the "for" loop within the code I have now?

Use a for loop to print one character at a time to the serial port, and get rid of the switch/case.

how should I let the for loop to be triggered by the potentiometer ?

How is the switch/case triggered by the potentiometer?

Take a look at conditional [u]if[/u] statments, as well as [u]and and or[/u] statements.

You are just sending out "o" over-and-over (which is good for looping), where the number of times you do that (the number of times you loop) depends on some condition.

While you're at it, take a look at while(), and do... while(), break and continue. There are different ways to loop and different ways to change the number of times you loop, or the conditions under which you continue to loop.

I combined the tone pitch follower code in the examples under digital with the switch case code under control.
im pretty sure its within this part of my code...

// these constants won't change:
const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 600; // sensor maximum, discovered through experiment

void setup() {
// initialize serial communication:
Serial.begin(9600);
}

void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// map the sensor range to a range of four options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 58);

int thisPitch = map(sensorReading, 0, 1023, 0, 500);

// play the pitch:
tone(8, thisPitch, 10);

That doesn't even compile - did you miss something out?

its not the whole code. its just the part where I think the potentiometer would be

Isn't that what sensorReading is?

int sensorReading = analogRead(A0);

that line ^

how could i have two analog reads controlling at the same time?

If you can explain what you mean by "controlling the same thing" means, and what that "same thing" is..?

int sensorReading = analogRead(A0);
its this line

how would i set up two analogreads to control the wave?

What does "control" mean to you in this context?

when i twist the potentiometer the sound's pitch is changed.
the wave of ooooo's goes from small to big like this

o
oo
ooo
oooo
ooooo
oooooo
ooooo
oooo
ooo
oo
ooo
oooo

I am controlling the pitch of the sound and the number of o's in the wave at the same time all with the potentiometer.

i want to have multiple potentiometers controlling these two things.

and i would also like to have more than one speaker making sound that will also have its pitch manipulated