LED Bar Graph with Corresponding Tones.

Hi,
I want to create an LED bar graph controlled by a potentiometer that plays a specific short tone every time an LED gets turned on. I would like to be able to have each LED have its own specific tone for each time it gets turned on, and perhaps when it gets turned off as well.

I have made a similar project before where Led’s would turn on along with a couple quick tones to make a clicking sound when it gets turned on:

#define TICK_PIN 12 //output pin for the speaker
#define LED_PINH 7 //output pin for the LED representing the letter “H”
#define LED_PINE 6 //output pin for the LED representing the letter “E”
#define LED_PINL 5 //output pin for the LED representing the 2nd letter “L”
#define LED_PINLII 4 //output pin for the LED representing the letter “L”
#define LED_PINO 3 //output pin for the LED representing the letter “O”

void setup()
{
pinMode(TICK_PIN,OUTPUT);
pinMode(LED_PINH,OUTPUT);
pinMode(LED_PINE,OUTPUT);
pinMode(LED_PINL,OUTPUT);
pinMode(LED_PINLII,OUTPUT);
pinMode(LED_PINO,OUTPUT);
for(int i = 0;i < 2;i++) //the number after the “<” symbol rep. how many-
//times the pattern will repeat.
//maybe repeat for a few hours?

{
delay(1000);
tone(TICK_PIN,900,1); //pitch controlled,duration in milliseconds
delay(30); //time between each small click
digitalWrite(LED_PINH, HIGH); //led turns on for letter “H”
tone(TICK_PIN,200,2); //“H” sound finished
delay(30);
tone(TICK_PIN,800,1);
delay(400);

tone(TICK_PIN,1000,1); //pitch controlled,duration in milliseconds
delay(30); //time between each small click
digitalWrite(LED_PINE, HIGH); //LED turns on for letter"E"
tone(TICK_PIN,200,2); //“E” sound finished
delay(30);
tone(TICK_PIN,500,1);
delay(500);

tone(TICK_PIN,1000,1); //pitch controlled,duration in milliseconds
delay(30); //time between each small click
digitalWrite(LED_PINL, HIGH); //led turns on for letter “L”
tone(TICK_PIN,200,2); //“L” sound finished
delay(30);
tone(TICK_PIN,1000,1);
delay(150);

tone(TICK_PIN,1000,1); //pitch controlled,duration in milliseconds
delay(30); //time between each small click
digitalWrite(LED_PINLII, HIGH); //led turns on for letter “L”
tone(TICK_PIN,200,2); //“L” sound finished
delay(30);
tone(TICK_PIN,1000,1);
delay(500);

tone(TICK_PIN,900,1); //pitch controlled,duration in milliseconds
delay(40); //time between each small click
digitalWrite(LED_PINO, HIGH); //led turns on for letter “O”
tone(TICK_PIN,600,1); //“O” sound finished

delay(2000); //time the letters stay lit
tone(TICK_PIN,350,2); //“backspace” is hit
delay(90);

digitalWrite(LED_PINO, LOW); //LED “0” turns off
delay(600); //lag as backspace is held in to erase letters
digitalWrite(LED_PINLII, LOW); //LED “L2” turns off
delay(100);
digitalWrite(LED_PINL, LOW); //LED “L” turns off
delay(100);
digitalWrite(LED_PINE, LOW); //LED “E” turns off
delay(100);
digitalWrite(LED_PINH, LOW); //LED “H” turns off
delay(200);
tone(TICK_PIN,1200,1); //backspace is released

delay(2000); //time before it starts up again

So, anyway, I would like to combine this with the Led Bar Graph, so that the LEDs and the tones don’t come on automatically, but only come on by turning the potentiometer.

Here is the LED Bar Graph that I was thinking of using (Its from a built in example):

const int analogPin = A0; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph

int ledPins = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11
}; // an array of pin numbers to which LEDs are attached

void setup() {
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}

void loop() {
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);

// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element’s index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}

Thank you, any guidance with this is very much appreciated!
-Jesse

Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

You need to use code tags, </>.

Tom… :slight_smile: