LED Audio Reader Thing
hey all,
so college student working on massive project, , need led array of sorts read audio imput , change color based on amplitude. unfortunately, reading amplitued of 0 always. code appreciated. , remember im civil engineering major, electronics , programming isnt forte!
pinout: 36 rgb leds
reds on digital 2-5
greens on 6-9
and blues on 10-13
my code:
//define leds , audio input respective pins
#define redled2 2
#define redled3 3
#define redled4 4
#define redled5 5
#define grnled6 6
#define grnled7 7
#define grnled8 8
#define grnled9 9
#define blueled10 10
#define blueled11 11
#define blueled12 12
#define blueled13 13
#define audioinput a1
//declare variables
int inputamplitude, aveampvalue, stepvalue;
int ampvalue0, ampvalue1, ampvalue2, ampvalue3, ampvalue4, ampvalue5, ampvalue6, ampvalue7;
void setup()
{
//establish each led pair output , turn off
for(int n = 2; n <= 13; n++)
{
pinmode(n, output);
digitalwrite(n, low);
}
//establish music input
pinmode(a1, input);
/*
serial port troubleshooting. serial port behavior commented out during run
faster led response time.
*/
serial.begin(9600);
}
void loop()
{
//read values of audio coming in, average them, use in loop function
ampvalue0 = analogread(audioinput);
delay(5);
ampvalue1 = analogread(audioinput);
delay(5);
ampvalue2 = analogread(audioinput);
delay(5);
ampvalue3 = analogread(audioinput);
delay(5);
ampvalue4 = analogread(audioinput);
delay(5);
ampvalue5 = analogread(audioinput);
delay(5);
ampvalue6 = analogread(audioinput);
delay(5);
ampvalue7 = analogread(audioinput);
delay(5);
aveampvalue = (ampvalue0 + ampvalue1 + ampvalue2 + ampvalue3 + ampvalue4 + ampvalue5 + ampvalue6 + ampvalue7)/8;
delay(5);
/*
set step value (how sensetive lights music) variable
of difference of first amplitude value , changing average
amplitude value.
*/
stepvalue = 2*abs(aveampvalue - inputamplitude);
//read amplitude of music
inputamplitude = analogread(audioinput);
serial.println(inputamplitude);
//troubleshooting output serial port
serial.print("inputamplitude is: ");
serial.println(inputamplitude);
if (analogread(audioinput) >= 50){
/*
make lights light according changes in music. by
comparing refreshing average amplitude first amplitude value
recieved in setup. based on how value different (the step
value), change lights either large factor or small one.
*/
if (inputamplitude<=10){digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled9, low);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
} digitalwrite(blueled13, low);
if(inputamplitude <= aveampvalue - stepvalue)
{
digitalwrite(redled2, high);
digitalwrite(redled3, high);
digitalwrite(redled4, high);
digitalwrite(redled5, high);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled9, low);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
digitalwrite(blueled13, low);
}
else if(inputamplitude <= aveampvalue)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled8, low);
digitalwrite(blueled10, high);
digitalwrite(blueled11, high);
digitalwrite(blueled12, high);
digitalwrite(blueled13, high);
}
else if(inputamplitude <= aveampvalue + stepvalue)
{
digitalwrite(redled2, high);
digitalwrite(redled3, high);
digitalwrite(redled4, high);
digitalwrite(redled5, high);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled9, low);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
digitalwrite(blueled13, low);
}
else if(inputamplitude <= aveampvalue + stepvalue*2)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, high);
digitalwrite(grnled7, high);
digitalwrite(grnled8, high);
digitalwrite(grnled9, high);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
digitalwrite(blueled13, low);
}
else if(inputamplitude <= aveampvalue + stepvalue*3)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, high);
digitalwrite(grnled7, high);
digitalwrite(grnled8, high);
digitalwrite(grnled9, high);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
digitalwrite(blueled13, low);
}
else if(inputamplitude <= aveampvalue + stepvalue*4)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, high);
digitalwrite(grnled7, high);
digitalwrite(grnled8, high);
digitalwrite(grnled9, high);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
digitalwrite(blueled13, low);
}
else if(inputamplitude <= aveampvalue + stepvalue*5)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled9, low);
digitalwrite(blueled10, high);
digitalwrite(blueled11, high);
digitalwrite(blueled12, high);
digitalwrite(blueled13, high);
}
else if(inputamplitude <= aveampvalue + stepvalue*6)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled9, low);
digitalwrite(blueled10, high);
digitalwrite(blueled11, high);
digitalwrite(blueled12, high);
digitalwrite(blueled13, high);
}
else
{
digitalwrite(redled2, high);
digitalwrite(redled3, high);
digitalwrite(redled4, high);
digitalwrite(redled5, low);
digitalwrite(grnled6, high);
digitalwrite(grnled7, high);
digitalwrite(grnled8, high);
digitalwrite(grnled9, low);
digitalwrite(blueled10, high);
digitalwrite(blueled11, high);
digitalwrite(blueled12, high);
digitalwrite(blueled13, low);
}
}
else{
digitalwrite(redled2, high);
digitalwrite(redled3, high);
digitalwrite(redled4, high);
digitalwrite(redled5, high);
digitalwrite(grnled6, high);
digitalwrite(grnled7, high);
digitalwrite(grnled8, high);
digitalwrite(grnled9, high);
digitalwrite(blueled10, high);
digitalwrite(blueled11, high);
digitalwrite(blueled12, high);
digitalwrite(blueled13, high);
}
delay(20);
}
thanks again!
so college student working on massive project, , need led array of sorts read audio imput , change color based on amplitude. unfortunately, reading amplitued of 0 always. code appreciated. , remember im civil engineering major, electronics , programming isnt forte!
pinout: 36 rgb leds
reds on digital 2-5
greens on 6-9
and blues on 10-13
my code:
//define leds , audio input respective pins
#define redled2 2
#define redled3 3
#define redled4 4
#define redled5 5
#define grnled6 6
#define grnled7 7
#define grnled8 8
#define grnled9 9
#define blueled10 10
#define blueled11 11
#define blueled12 12
#define blueled13 13
#define audioinput a1
//declare variables
int inputamplitude, aveampvalue, stepvalue;
int ampvalue0, ampvalue1, ampvalue2, ampvalue3, ampvalue4, ampvalue5, ampvalue6, ampvalue7;
void setup()
{
//establish each led pair output , turn off
for(int n = 2; n <= 13; n++)
{
pinmode(n, output);
digitalwrite(n, low);
}
//establish music input
pinmode(a1, input);
/*
serial port troubleshooting. serial port behavior commented out during run
faster led response time.
*/
serial.begin(9600);
}
void loop()
{
//read values of audio coming in, average them, use in loop function
ampvalue0 = analogread(audioinput);
delay(5);
ampvalue1 = analogread(audioinput);
delay(5);
ampvalue2 = analogread(audioinput);
delay(5);
ampvalue3 = analogread(audioinput);
delay(5);
ampvalue4 = analogread(audioinput);
delay(5);
ampvalue5 = analogread(audioinput);
delay(5);
ampvalue6 = analogread(audioinput);
delay(5);
ampvalue7 = analogread(audioinput);
delay(5);
aveampvalue = (ampvalue0 + ampvalue1 + ampvalue2 + ampvalue3 + ampvalue4 + ampvalue5 + ampvalue6 + ampvalue7)/8;
delay(5);
/*
set step value (how sensetive lights music) variable
of difference of first amplitude value , changing average
amplitude value.
*/
stepvalue = 2*abs(aveampvalue - inputamplitude);
//read amplitude of music
inputamplitude = analogread(audioinput);
serial.println(inputamplitude);
//troubleshooting output serial port
serial.print("inputamplitude is: ");
serial.println(inputamplitude);
if (analogread(audioinput) >= 50){
/*
make lights light according changes in music. by
comparing refreshing average amplitude first amplitude value
recieved in setup. based on how value different (the step
value), change lights either large factor or small one.
*/
if (inputamplitude<=10){digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled9, low);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
} digitalwrite(blueled13, low);
if(inputamplitude <= aveampvalue - stepvalue)
{
digitalwrite(redled2, high);
digitalwrite(redled3, high);
digitalwrite(redled4, high);
digitalwrite(redled5, high);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled9, low);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
digitalwrite(blueled13, low);
}
else if(inputamplitude <= aveampvalue)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled8, low);
digitalwrite(blueled10, high);
digitalwrite(blueled11, high);
digitalwrite(blueled12, high);
digitalwrite(blueled13, high);
}
else if(inputamplitude <= aveampvalue + stepvalue)
{
digitalwrite(redled2, high);
digitalwrite(redled3, high);
digitalwrite(redled4, high);
digitalwrite(redled5, high);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled9, low);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
digitalwrite(blueled13, low);
}
else if(inputamplitude <= aveampvalue + stepvalue*2)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, high);
digitalwrite(grnled7, high);
digitalwrite(grnled8, high);
digitalwrite(grnled9, high);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
digitalwrite(blueled13, low);
}
else if(inputamplitude <= aveampvalue + stepvalue*3)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, high);
digitalwrite(grnled7, high);
digitalwrite(grnled8, high);
digitalwrite(grnled9, high);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
digitalwrite(blueled13, low);
}
else if(inputamplitude <= aveampvalue + stepvalue*4)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, high);
digitalwrite(grnled7, high);
digitalwrite(grnled8, high);
digitalwrite(grnled9, high);
digitalwrite(blueled10, low);
digitalwrite(blueled11, low);
digitalwrite(blueled12, low);
digitalwrite(blueled13, low);
}
else if(inputamplitude <= aveampvalue + stepvalue*5)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled9, low);
digitalwrite(blueled10, high);
digitalwrite(blueled11, high);
digitalwrite(blueled12, high);
digitalwrite(blueled13, high);
}
else if(inputamplitude <= aveampvalue + stepvalue*6)
{
digitalwrite(redled2, low);
digitalwrite(redled3, low);
digitalwrite(redled4, low);
digitalwrite(redled5, low);
digitalwrite(grnled6, low);
digitalwrite(grnled7, low);
digitalwrite(grnled8, low);
digitalwrite(grnled9, low);
digitalwrite(blueled10, high);
digitalwrite(blueled11, high);
digitalwrite(blueled12, high);
digitalwrite(blueled13, high);
}
else
{
digitalwrite(redled2, high);
digitalwrite(redled3, high);
digitalwrite(redled4, high);
digitalwrite(redled5, low);
digitalwrite(grnled6, high);
digitalwrite(grnled7, high);
digitalwrite(grnled8, high);
digitalwrite(grnled9, low);
digitalwrite(blueled10, high);
digitalwrite(blueled11, high);
digitalwrite(blueled12, high);
digitalwrite(blueled13, low);
}
}
else{
digitalwrite(redled2, high);
digitalwrite(redled3, high);
digitalwrite(redled4, high);
digitalwrite(redled5, high);
digitalwrite(grnled6, high);
digitalwrite(grnled7, high);
digitalwrite(grnled8, high);
digitalwrite(grnled9, high);
digitalwrite(blueled10, high);
digitalwrite(blueled11, high);
digitalwrite(blueled12, high);
digitalwrite(blueled13, high);
}
delay(20);
}
thanks again!
hi, if want chance of on this, need read "how use forum - please read." message first. haven't , bet that's why no-one has responded yet.
you need edit original post, enclose sketch within code tags (see # button) , explain circuit more clearly, including schematic or @ least clear picture. brief description confusing , seems contradict (e.g. number of leds). schematic can hand-drawn long clear (as civil engineering student should understand how important diagrams are).
you amplitude reading zero, points problem part of circuit feeds audio signal arduino, , have told nothing yet.
paul
you need edit original post, enclose sketch within code tags (see # button) , explain circuit more clearly, including schematic or @ least clear picture. brief description confusing , seems contradict (e.g. number of leds). schematic can hand-drawn long clear (as civil engineering student should understand how important diagrams are).
you amplitude reading zero, points problem part of circuit feeds audio signal arduino, , have told nothing yet.
paul
Arduino Forum > Using Arduino > LEDs and Multiplexing > LED Audio Reader Thing
arduino
Comments
Post a Comment