I want to change the way the neopixels light up on my Tie.
I'm wanting all the neopixels in one color (red), and to get brighter as the sound increased to the microphone.
Example:
When no sound, no lit neopixels.
When little sound, all neopixels dimly lit in red color.
When max sound, all neopixels brightly lit in red color.
Can someone help me with writing the program?
LED Ampli-Tie
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: LED Ampli-Tie
See if this does what you want. Note: I haven't actually run this because I don't have all the parts here with me, but it ought to be close. You may have to play with it a bit.
Code: Select all
/*
LED VU meter for Arduino and Adafruit NeoPixel LEDs.
Hardware requirements:
- Most Arduino or Arduino-compatible boards (ATmega 328P or better).
- Adafruit Electret Microphone Amplifier (ID: 1063)
- Adafruit Flora RGB Smart Pixels (ID: 1260)
OR
- Adafruit NeoPixel Digital LED strip (ID: 1138)
- Optional: battery for portable use (else power through USB or adapter)
Software requirements:
- Adafruit NeoPixel library
Connections:
- 3.3V to mic amp +
- GND to mic amp -
- Analog pin to microphone output (configurable below)
- Digital pin to LED data input (configurable below)
See notes in setup() regarding 5V vs. 3.3V boards - there may be an
extra connection to make and one line of code to enable or disable.
Written by Adafruit Industries. Distributed under the BSD license.
This paragraph must be included in any redistribution.
*/
#include <Adafruit_NeoPixel.h>
#define N_PIXELS 16 // Number of pixels in strand
#define MIC_PIN A9 // Microphone is attached to this analog pin
#define LED_PIN 6 // NeoPixel LED strand is connected to this pin
#define DC_OFFSET 0 // DC offset in mic signal - if unusure, leave 0
#define NOISE 10 // Noise/hum/interference in mic signal
#define SAMPLES 60 // Length of buffer for dynamic level adjustment
#define TOP (N_PIXELS + 2) // Allow dot to go slightly off scale
#define PEAK_FALL 40 // Rate of peak falling dot
byte
peak = 0, // Used for falling dot
dotCount = 0, // Frame counter for delaying dot-falling speed
volCount = 0; // Frame counter for storing past volume data
int
vol[SAMPLES], // Collection of prior volume samples
lvl = 10, // Current "dampened" audio level
minLvlAvg = 0, // For dynamic adjustment of graph low & high
maxLvlAvg = 512;
Adafruit_NeoPixel
strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// This is only needed on 5V Arduinos (Uno, Leonardo, etc.).
// Connect 3.3V to mic AND TO AREF ON ARDUINO and enable this
// line. Audio samples are 'cleaner' at 3.3V.
// COMMENT OUT THIS LINE FOR 3.3V ARDUINOS (FLORA, ETC.):
// analogReference(EXTERNAL);
memset(vol, 0, sizeof(vol));
strip.begin();
for (int i = 0; i < N_PIXELS; i++)
{
strip.setPixelColor(i, 255, 0, 0); //set all pixels to red
}
strip.setBrightness(0); //turn all pixels off
strip.show(); //update strip
}
void loop() {
uint8_t i;
uint16_t minLvl, maxLvl;
int n, bright;
n = analogRead(MIC_PIN); // Raw reading from mic
n = abs(n - 512 - DC_OFFSET); // Center on zero
n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum
lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy)
// Calculate brightness based on dynamic min/max levels (fixed point):
bright = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg);
if(bright < 0L) bright = 0; // Clip output
else if(bright > TOP) bright = TOP;
if(bright > peak) peak = bright; // Keep 'peak' dot at top
strip.setBrightness(bright);
strip.show(); // Update strip
vol[volCount] = n; // Save sample for dynamic leveling
if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter
// Get volume range of prior frames
minLvl = maxLvl = vol[0];
for(i=1; i<SAMPLES; i++) {
if(vol[i] < minLvl) minLvl = vol[i];
else if(vol[i] > maxLvl) maxLvl = vol[i];
}
// minLvl and maxLvl indicate the volume range over prior frames, used
// for vertically scaling the output graph (so it looks interesting
// regardless of volume level). If they're too close together though
// (e.g. at very low volume levels) the graph becomes super coarse
// and 'jumpy'...so keep some minimum distance between them (this
// also lets the graph go to zero when no sound is playing):
if((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP;
minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels
maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average)
}
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
- superprojb
- Posts: 51
- Joined: Wed Mar 05, 2014 11:22 pm
Re: LED Ampli-Tie
Thank you for the quick reply. After installing the code, none of the neopixels light up, regardless of the level sound input at the microphone.
I tried changing a few values, but I'm not seeing my issue to get some neopixels to light up. I did reload the Ampli-tie code and it works, but switching back to new code, nothing is lighting up.
Any ideas or suggestion are welcomed. Thank you in advance.
I tried changing a few values, but I'm not seeing my issue to get some neopixels to light up. I did reload the Ampli-tie code and it works, but switching back to new code, nothing is lighting up.
Any ideas or suggestion are welcomed. Thank you in advance.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: LED Ampli-Tie
Sorry - my mistake. I forgot how setBrightness worked...
Try this:
Try this:
Code: Select all
/*
LED VU meter for Arduino and Adafruit NeoPixel LEDs.
Hardware requirements:
- Most Arduino or Arduino-compatible boards (ATmega 328P or better).
- Adafruit Electret Microphone Amplifier (ID: 1063)
- Adafruit Flora RGB Smart Pixels (ID: 1260)
OR
- Adafruit NeoPixel Digital LED strip (ID: 1138)
- Optional: battery for portable use (else power through USB or adapter)
Software requirements:
- Adafruit NeoPixel library
Connections:
- 3.3V to mic amp +
- GND to mic amp -
- Analog pin to microphone output (configurable below)
- Digital pin to LED data input (configurable below)
See notes in setup() regarding 5V vs. 3.3V boards - there may be an
extra connection to make and one line of code to enable or disable.
Written by Adafruit Industries. Distributed under the BSD license.
This paragraph must be included in any redistribution.
*/
#include <Adafruit_NeoPixel.h>
#define N_PIXELS 16 // Number of pixels in strand
#define MIC_PIN A9 // Microphone is attached to this analog pin
#define LED_PIN 6 // NeoPixel LED strand is connected to this pin
#define DC_OFFSET 0 // DC offset in mic signal - if unusure, leave 0
#define NOISE 10 // Noise/hum/interference in mic signal
#define SAMPLES 60 // Length of buffer for dynamic level adjustment
#define TOP (N_PIXELS + 2) // Allow dot to go slightly off scale
#define PEAK_FALL 40 // Rate of peak falling dot
byte
peak = 0, // Used for falling dot
dotCount = 0, // Frame counter for delaying dot-falling speed
volCount = 0; // Frame counter for storing past volume data
int
vol[SAMPLES], // Collection of prior volume samples
lvl = 10, // Current "dampened" audio level
minLvlAvg = 0, // For dynamic adjustment of graph low & high
maxLvlAvg = 512;
Adafruit_NeoPixel
strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// This is only needed on 5V Arduinos (Uno, Leonardo, etc.).
// Connect 3.3V to mic AND TO AREF ON ARDUINO and enable this
// line. Audio samples are 'cleaner' at 3.3V.
// COMMENT OUT THIS LINE FOR 3.3V ARDUINOS (FLORA, ETC.):
// analogReference(EXTERNAL);
memset(vol, 0, sizeof(vol));
strip.begin();
for (int i = 0; i < N_PIXELS; i++)
{
strip.setPixelColor(i, 0, 0, 0); //turn off all pixels
}
strip.show(); //update strip
}
void loop() {
uint8_t i;
uint16_t minLvl, maxLvl;
int n, bright;
n = analogRead(MIC_PIN); // Raw reading from mic
n = abs(n - 512 - DC_OFFSET); // Center on zero
n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum
lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy)
// Calculate brightness based on dynamic min/max levels (fixed point):
bright = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg);
if(bright < 0L) bright = 0; // Clip output
else if(bright > TOP) bright = TOP;
if(bright > peak) peak = bright; // Keep 'peak' dot at top
strip.setBrightness(bright);
for (int i = 0; i < N_PIXELS; i++)
{
strip.setPixelColor(i, 255, 0, 0); //set all pixels to red
}
strip.show(); // Update strip
vol[volCount] = n; // Save sample for dynamic leveling
if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter
// Get volume range of prior frames
minLvl = maxLvl = vol[0];
for(i=1; i<SAMPLES; i++) {
if(vol[i] < minLvl) minLvl = vol[i];
else if(vol[i] > maxLvl) maxLvl = vol[i];
}
// minLvl and maxLvl indicate the volume range over prior frames, used
// for vertically scaling the output graph (so it looks interesting
// regardless of volume level). If they're too close together though
// (e.g. at very low volume levels) the graph becomes super coarse
// and 'jumpy'...so keep some minimum distance between them (this
// also lets the graph go to zero when no sound is playing):
if((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP;
minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels
maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average)
}
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
- superprojb
- Posts: 51
- Joined: Wed Mar 05, 2014 11:22 pm
Re: LED Ampli-Tie
AWESOME!!! It works!! =)
- superprojb
- Posts: 51
- Joined: Wed Mar 05, 2014 11:22 pm
Re: LED Ampli-Tie
Rick, thank you again!
I have one last configuration to ask for your help Ok, this one works like the Ampli-tie, but all colors are red, and the max Neopixel is white.
So, instead of the multi-colors, only a red color for all Neopixels, but the max Neopixel to be white. Dont change the action, but only the colors to red and white?
I will be making 2 each of the different (3 styles) Ampli-ties for Graduation. Thank you in advance and thank you Adafruit! =)
I have one last configuration to ask for your help Ok, this one works like the Ampli-tie, but all colors are red, and the max Neopixel is white.
So, instead of the multi-colors, only a red color for all Neopixels, but the max Neopixel to be white. Dont change the action, but only the colors to red and white?
I will be making 2 each of the different (3 styles) Ampli-ties for Graduation. Thank you in advance and thank you Adafruit! =)
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: LED Ampli-Tie
Code: Select all
/*
LED VU meter for Arduino and Adafruit NeoPixel LEDs.
Hardware requirements:
- Most Arduino or Arduino-compatible boards (ATmega 328P or better).
- Adafruit Electret Microphone Amplifier (ID: 1063)
- Adafruit Flora RGB Smart Pixels (ID: 1260)
OR
- Adafruit NeoPixel Digital LED strip (ID: 1138)
- Optional: battery for portable use (else power through USB or adapter)
Software requirements:
- Adafruit NeoPixel library
Connections:
- 3.3V to mic amp +
- GND to mic amp -
- Analog pin to microphone output (configurable below)
- Digital pin to LED data input (configurable below)
See notes in setup() regarding 5V vs. 3.3V boards - there may be an
extra connection to make and one line of code to enable or disable.
Written by Adafruit Industries. Distributed under the BSD license.
This paragraph must be included in any redistribution.
*/
#include <Adafruit_NeoPixel.h>
#define N_PIXELS 16 // Number of pixels in strand
#define MIC_PIN A9 // Microphone is attached to this analog pin
#define LED_PIN 6 // NeoPixel LED strand is connected to this pin
#define DC_OFFSET 0 // DC offset in mic signal - if unusure, leave 0
#define NOISE 10 // Noise/hum/interference in mic signal
#define SAMPLES 60 // Length of buffer for dynamic level adjustment
#define TOP (N_PIXELS + 2) // Allow dot to go slightly off scale
#define PEAK_FALL 40 // Rate of peak falling dot
byte
peak = 0, // Used for falling dot
dotCount = 0, // Frame counter for delaying dot-falling speed
volCount = 0; // Frame counter for storing past volume data
int
vol[SAMPLES], // Collection of prior volume samples
lvl = 10, // Current "dampened" audio level
minLvlAvg = 0, // For dynamic adjustment of graph low & high
maxLvlAvg = 512;
Adafruit_NeoPixel
strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// This is only needed on 5V Arduinos (Uno, Leonardo, etc.).
// Connect 3.3V to mic AND TO AREF ON ARDUINO and enable this
// line. Audio samples are 'cleaner' at 3.3V.
// COMMENT OUT THIS LINE FOR 3.3V ARDUINOS (FLORA, ETC.):
// analogReference(EXTERNAL);
memset(vol, 0, sizeof(vol));
strip.begin();
}
void loop() {
uint8_t i;
uint16_t minLvl, maxLvl;
int n, height;
n = analogRead(MIC_PIN); // Raw reading from mic
n = abs(n - 512 - DC_OFFSET); // Center on zero
n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum
lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy)
// Calculate bar height based on dynamic min/max levels (fixed point):
height = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg);
if(height < 0L) height = 0; // Clip output
else if(height > TOP) height = TOP;
if(height > peak) peak = height; // Keep 'peak' dot at top
// Color pixels based on rainbow gradient
for(i=0; i<N_PIXELS; i++) {
if(i >= height) strip.setPixelColor(i, 0, 0, 0);
else strip.setPixelColor(i, 255, 0, 0);
}
// Draw peak dot
if(peak > 0 && peak <= N_PIXELS-1) strip.setPixelColor(peak, 255, 255, 255);
strip.show(); // Update strip
// Every few frames, make the peak pixel drop by 1:
if(++dotCount >= PEAK_FALL) { //fall rate
if(peak > 0) peak--;
dotCount = 0;
}
vol[volCount] = n; // Save sample for dynamic leveling
if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter
// Get volume range of prior frames
minLvl = maxLvl = vol[0];
for(i=1; i<SAMPLES; i++) {
if(vol[i] < minLvl) minLvl = vol[i];
else if(vol[i] > maxLvl) maxLvl = vol[i];
}
// minLvl and maxLvl indicate the volume range over prior frames, used
// for vertically scaling the output graph (so it looks interesting
// regardless of volume level). If they're too close together though
// (e.g. at very low volume levels) the graph becomes super coarse
// and 'jumpy'...so keep some minimum distance between them (this
// also lets the graph go to zero when no sound is playing):
if((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP;
minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels
maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average)
}
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
- superprojb
- Posts: 51
- Joined: Wed Mar 05, 2014 11:22 pm
Re: LED Ampli-Tie
Rick, you may not hear it enough, but I want to thank you for your prompt, professional, and expert help in my Adafruit service form topic. You have provided great customer service/support that exceeded my expiations.
I believe a company that sells its own products is only as good as its customer service/support. It’s the support after the sale that keeps the customers satisfied and helps grow your future sales.
I am 100% satisfied with Adafruit’s product design/production, quality control, sales, shipping, and your service/support Rick.
I will be a customer for life! Thank you Rick and Adafruit.
I believe a company that sells its own products is only as good as its customer service/support. It’s the support after the sale that keeps the customers satisfied and helps grow your future sales.
I am 100% satisfied with Adafruit’s product design/production, quality control, sales, shipping, and your service/support Rick.
I will be a customer for life! Thank you Rick and Adafruit.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: LED Ampli-Tie
You're welcome!
- superprojb
- Posts: 51
- Joined: Wed Mar 05, 2014 11:22 pm
Re: LED Ampli-Tie
I need to power up a 2nd strand of neo pixels to have the same program, but with a green color.
Is it possible to modify this Flora program to have a 2nd output for the 2nd strand of green neo pixels? (same progam for the red, but with a green color & on a different output pin)
So... I need the Flora to output #6 pin for the red strand of neo pixels, and output #12 pin output for the green strand of neo pixels.
Is it possible to modify this Flora program to have a 2nd output for the 2nd strand of green neo pixels? (same progam for the red, but with a green color & on a different output pin)
So... I need the Flora to output #6 pin for the red strand of neo pixels, and output #12 pin output for the green strand of neo pixels.
Code: Select all
/*
LED VU meter for Arduino and Adafruit NeoPixel LEDs.
Hardware requirements:
- Most Arduino or Arduino-compatible boards (ATmega 328P or better).
- Adafruit Electret Microphone Amplifier (ID: 1063)
- Adafruit Flora RGB Smart Pixels (ID: 1260)
OR
- Adafruit NeoPixel Digital LED strip (ID: 1138)
- Optional: battery for portable use (else power through USB or adapter)
Software requirements:
- Adafruit NeoPixel library
Connections:
- 3.3V to mic amp +
- GND to mic amp -
- Analog pin to microphone output (configurable below)
- Digital pin to LED data input (configurable below)
See notes in setup() regarding 5V vs. 3.3V boards - there may be an
extra connection to make and one line of code to enable or disable.
Written by Adafruit Industries. Distributed under the BSD license.
This paragraph must be included in any redistribution.
*/
#include <Adafruit_NeoPixel.h>
#define N_PIXELS 16 // Number of pixels in strand
#define MIC_PIN A9 // Microphone is attached to this analog pin
#define LED_PIN 6 // NeoPixel LED strand is connected to this pin
#define DC_OFFSET 0 // DC offset in mic signal - if unusure, leave 0
#define NOISE 10 // Noise/hum/interference in mic signal
#define SAMPLES 60 // Length of buffer for dynamic level adjustment
#define TOP (N_PIXELS + 2) // Allow dot to go slightly off scale
#define PEAK_FALL 40 // Rate of peak falling dot
byte
peak = 0, // Used for falling dot
dotCount = 0, // Frame counter for delaying dot-falling speed
volCount = 0; // Frame counter for storing past volume data
int
vol[SAMPLES], // Collection of prior volume samples
lvl = 10, // Current "dampened" audio level
minLvlAvg = 0, // For dynamic adjustment of graph low & high
maxLvlAvg = 512;
Adafruit_NeoPixel
strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// This is only needed on 5V Arduinos (Uno, Leonardo, etc.).
// Connect 3.3V to mic AND TO AREF ON ARDUINO and enable this
// line. Audio samples are 'cleaner' at 3.3V.
// COMMENT OUT THIS LINE FOR 3.3V ARDUINOS (FLORA, ETC.):
// analogReference(EXTERNAL);
memset(vol, 0, sizeof(vol));
strip.begin();
for (int i = 0; i < N_PIXELS; i++)
{
strip.setPixelColor(i, 0, 0, 0); //turn off all pixels
}
strip.show(); //update strip
}
void loop() {
uint8_t i;
uint16_t minLvl, maxLvl;
int n, bright;
n = analogRead(MIC_PIN); // Raw reading from mic
n = abs(n - 512 - DC_OFFSET); // Center on zero
n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum
lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy)
// Calculate brightness based on dynamic min/max levels (fixed point):
bright = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg);
if(bright < 0L) bright = 0; // Clip output
else if(bright > TOP) bright = TOP;
if(bright > peak) peak = bright; // Keep 'peak' dot at top
strip.setBrightness(bright);
for (int i = 0; i < N_PIXELS; i++)
{
strip.setPixelColor(i, 255, 0, 0); //set all pixels to red
}
strip.show(); // Update strip
vol[volCount] = n; // Save sample for dynamic leveling
if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter
// Get volume range of prior frames
minLvl = maxLvl = vol[0];
for(i=1; i<SAMPLES; i++) {
if(vol[i] < minLvl) minLvl = vol[i];
else if(vol[i] > maxLvl) maxLvl = vol[i];
}
// minLvl and maxLvl indicate the volume range over prior frames, used
// for vertically scaling the output graph (so it looks interesting
// regardless of volume level). If they're too close together though
// (e.g. at very low volume levels) the graph becomes super coarse
// and 'jumpy'...so keep some minimum distance between them (this
// also lets the graph go to zero when no sound is playing):
if((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP;
minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels
maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average)
}
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
Last edited by adafruit_support_rick on Sun May 04, 2014 3:07 pm, edited 1 time in total.
Reason: please use Code tags when posting code (</> button)
Reason: please use Code tags when posting code (</> button)
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: LED Ampli-Tie
Declare two NeoPixel objects:
Wherever you have "strip", change it to "stripRed". Then add another identical line, but for "stripGreen"
Code: Select all
#define N_RED_PIXELS 16 // Number of pixels in strand
#define RED_PIN 6 // Red NeoPixel LED strand is connected to this pin
#define N_GREEN_PIXELS 16 // Number of pixels in strand
#define GREEN_PIN 12 // Green NeoPixel LED strand is connected to this pin
Adafruit_NeoPixel stripRed = Adafruit_NeoPixel(N_RED_PIXELS, RED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripGreen= Adafruit_NeoPixel(N_GREEN_PIXELS, GREEN_PIN, NEO_GRB + NEO_KHZ800);
- superprojb
- Posts: 51
- Joined: Wed Mar 05, 2014 11:22 pm
Re: LED Ampli-Tie
I have tried to make all the changes, but I keep getting a error when I start to upload.
'stripRed' not declared in this scope
Can someone help correct the issue?
'stripRed' not declared in this scope
Can someone help correct the issue?
Code: Select all
/*
LED VU meter for Arduino and Adafruit NeoPixel LEDs.
Hardware requirements:
- Most Arduino or Arduino-compatible boards (ATmega 328P or better).
- Adafruit Electret Microphone Amplifier (ID: 1063)
- Adafruit Flora RGB Smart Pixels (ID: 1260)
OR
- Adafruit NeoPixel Digital LED strip (ID: 1138)
- Optional: battery for portable use (else power through USB or adapter)
Software requirements:
- Adafruit NeoPixel library
Connections:
- 3.3V to mic amp +
- GND to mic amp -
- Analog pin to microphone output (configurable below)
- Digital pin to LED data input (configurable below)
See notes in setup() regarding 5V vs. 3.3V boards - there may be an
extra connection to make and one line of code to enable or disable.
Written by Adafruit Industries. Distributed under the BSD license.
This paragraph must be included in any redistribution.
*/
#include <Adafruit_NeoPixel.h>
#define N_RED_PIXELS 16 // Number of RED pixels in strand
#define N_GREEN_PIXELS 16 // Number of GREEN pixels in strand
#define MIC_PIN A9 // Microphone is attached to this analog pin
#define RED_PIN 6 // NeoPixel RED strand is connected to this pin
#define GREEN_PIN 12 // NeoPixel GREEN strand is connected to this pin
#define DC_OFFSET 10 // DC offset in mic signal - if unusure, leave 0
#define NOISE 24 // Noise/hum/interference in mic signal
#define SAMPLES 60 // Length of buffer for dynamic level adjustment
#define TOP (N_PIXELS + 2) // Allow dot to go slightly off scale
#define PEAK_FALL 40 // Rate of peak falling dot
byte
peak = 0, // Used for falling dot
dotCount = 0, // Frame counter for delaying dot-falling speed
volCount = 0; // Frame counter for storing past volume data
int
vol[SAMPLES], // Collection of prior volume samples
lvl = 1, // Current "dampened" audio level
minLvlAvg = 0, // For dynamic adjustment of graph low & high
maxLvlAvg = 512;
Adafruit_NeoPixel stripRed = Adafruit_NeoPixel(N_RED_PIXELS, RED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripGREEN = Adafruit_NeoPixel(N_GREEN_PIXELS, GREEN_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// This is only needed on 5V Arduinos (Uno, Leonardo, etc.).
// Connect 3.3V to mic AND TO AREF ON ARDUINO and enable this
// line. Audio samples are 'cleaner' at 3.3V.
// COMMENT OUT THIS LINE FOR 3.3V ARDUINOS (FLORA, ETC.):
// analogReference(EXTERNAL);
memset(vol, 0, sizeof(vol));
stripRED.begin();
stripGREEN.begin();
}
void loop() {
uint8_t i;
uint16_t minLvl, maxLvl;
int n, height;
n = analogRead(MIC_PIN); // Raw reading from mic
n = abs(n - 512 - DC_OFFSET); // Center on zero
n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum
lvl = ((lvl * 6) + n) >> 3; // "Dampened" reading (else looks twitchy)
// Calculate bar height based on dynamic min/max levels (fixed point):
height = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg);
if(height < 0L) height = 0; // Clip output
else if(height > TOP) height = TOP;
if(height > peak) peak = height; // Keep 'peak' dot at top
// Color pixels based on rainbow gradient
for(i=0; i<N_PIXELS; i++) {
if(i >= height) stripRED.setPixelColor(i, 0, 0, 0) stripGREEN.setPixelColor(i, 0, 0, 0);
else stripRED.setPixelColor(i, 255, 0, 0) stripGREEN.setPixelColor(i, 255, 0, 0);
}
// Draw peak dot
if(peak > 0 && peak <= N_PIXELS-1) stripRED.setPixelColor(peak, 255, 255, 255) stripGREEN.setPixelColor(peak, 255, 255, 255);
stripRED.show() stripGREEN.show(); // Update strip
// Every few frames, make the peak pixel drop by 1:
if(++dotCount >= PEAK_FALL) { //fall rate
if(peak > 0) peak--;
dotCount = 0;
}
vol[volCount] = n; // Save sample for dynamic leveling
if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter
// Get volume range of prior frames
minLvl = maxLvl = vol[0];
for(i=1; i<SAMPLES; i++) {
if(vol[i] < minLvl) minLvl = vol[i];
else if(vol[i] > maxLvl) maxLvl = vol[i];
}
// minLvl and maxLvl indicate the volume range over prior frames, used
// for vertically scaling the output graph (so it looks interesting
// regardless of volume level). If they're too close together though
// (e.g. at very low volume levels) the graph becomes super coarse
// and 'jumpy'...so keep some minimum distance between them (this
// also lets the graph go to zero when no sound is playing):
if((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP;
minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels
maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average)
}
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return stripRED.Color(WheelPos * 3, 255 - WheelPos * 3, 0) stripGREEN.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return stripRED.Color(255 - WheelPos * 3, 0, WheelPos * 3) stripGREEN.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return stripRED.Color(0, WheelPos * 3, 255 - WheelPos * 3) stripGREEN.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: LED Ampli-Tie
You are referring to "stripRED" in the code:
But you're declared it as "stripRed"
Capitalization counts.
Code: Select all
stripRED.begin();
Code: Select all
Adafruit_NeoPixel stripRed = Adafruit_NeoPixel(N_RED_PIXELS, RED_PIN, NEO_GRB + NEO_KHZ800);
- superprojb
- Posts: 51
- Joined: Wed Mar 05, 2014 11:22 pm
Re: LED Ampli-Tie
My mistake. I made the correction, now there is another error.
N_PIXELS was not declared
N_PIXELS was not declared
- Attachments
-
- Adafruit_1.jpg (48.29 KiB) Viewed 275 times
Please be positive and constructive with your questions and comments.