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.