TonePitchFollower with multiple speakers

/*
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.

*/

// 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, 59);

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;

}

}

also when i set up more than 58 cases the serial monitor doesnt stream any of the o's.

ideally i would like to have more than 58 o's.

im curious if there could be a way to have more.

i remember when i had set up about 60 + cases I would get very weird symbols like @% ^%*# or even symbols that aren't on the keyboard

im curious if there could be a way to have more.

i remember when i had set up about 60 + case

Which is why you should go back and read reply #1.

Please, please, use tags when posting code.

I would get very weird symbols like @% ^%*# or even symbols that aren't on the keyboard

That's probably your program running out of RAM, which is why you should be using for loops

ill keep that in mind sorry.

ive when i looked at the for loop link

i couldnt figure out ho i would go about applying it to my code

i couldnt figure out ho i would go about applying it to my code

If you want to print one 'o', loop once.
If you want to print two 'o's, loop twice.
Can you see where this is leading?

im looking here
http://arduino.cc/en/Reference/For

ive read about a pwm pin. im not sure what this is but it reminds me of a potentiometer.
this make me think in that sketch the LED would be dimmed by the pwm pin?

I'm really not sure what you're talking about here.
Yes, a PWM pin will allow you to dim an LED, but what that has got to do with printing 'o's, I'm unclear.

// Dim an LED using a PWM pin
int PWMpin = 10; // LED in series with 470 ohm resistor on pin 10

void setup()
{
  // no setup needed
}

void loop()
{
   int x = 1;
   for (int i = 0; i > -1; i = i + x){
      analogWrite(PWMpin, i);
      if (i == 255) x = -1;             // switch direction at peak
      delay(10);
   } 
}

ive got the led dimming on and off.
can this be be controlled by the potentiometer?
how would i make this print "o's" to the serial monitor ?

when i first read over and saw PMW pin. it made me think it was something like the potentiometer. i didnt relies it was just a pin on the arduino shield.

can this be be controlled by the potentiometer?

Yes

how would i make this print "o's" to the serial monitor ?

With a simple for loop

when i first read over and saw PMW pin. it made me think it was something like the potentiometer. i didnt relies it was just a pin on the arduino shield.

I don't understand this.

dont worry about the pmw questions i was confused what it was...

so i have the led on a loop and it is dimming on and off repeatedly.

i need a speaker to eventually replace the light and have it pitch controlled.

what should i do next?

"o's" , potentiometer, or the speaker?

i think when you originally told me to use the for loop code, it was because of the switch case sketch and all of the o's within the code.

the other part of the code was the tone pitch follower.

the tone pitch follower i dont think would need a for loop. its a pretty small amount of code.

what should i do next?

I haven't the slightest idea.
What do you want to do? - you seem to be dancing about all over the place.

could you help me figure out how to set up the potentiometer to dim the led? and set up the potentiometer to print o's?

could you help me figure out how to set up the potentiometer to dim the led?

Have you looked through the examples?

i dont see anything about potentiometers in this tutorial

i dont see anything about potentiometers in this tutorial

I take it you were expecting to?

Have you actually looked at any of the programming EXAMPLES?

yes i have looked at the arduino examples. thats where i got a lot of my code i posted the first time

I'm fairly sure there's an example showing how to dim a LED.
I'm almost certain there's one that shows how to read a potentiometer.
There may even be one that does both.

i can fade the led with potentiometer

trying to print o's if i can figure it out