Hello everyone,
I made a small circuit that has a microphone MAX9814 , an Neopixel ring 32 LEDS, and Arduino UNO R3.
Here is my code:
#include <Adafruit_NeoPixel.h>
#define PIN 6 // Pin where the NeoPixel is connected
#define NUMPIXELS 16 // Number of pixels in the pixels
#define AUDIO_PIN A0 // Pin where the audio input is connected
#define DELAYVAL 1 // Time (in milliseconds) to pause between pixels
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin();
pixels.show(); // Initialize all pixels to 'off'
Serial.begin(9600);
}
void loop() {
while (1 > 0) {
// Clear the pixels first
pixels.clear();
pixels.setBrightness(100);
int audioValue = analogRead(AUDIO_PIN);
// Map the audio value to the number of LEDs to light up
int numLedsToLight = map(audioValue, 0, 1023, 0, NUMPIXELS);
// Light up the LEDs based on audio level
for (int i = 0; i < numLedsToLight; i++) {
//light only the current pixel
if (i < 16) { pixels.setPixelColor(i, pixels.gamma32(pixels.Color(0, 96, 2)));} //Dark Green
else if (i < 21) { pixels.setPixelColor(i, pixels.gamma32(pixels.Color(0, 96, 2)));} //Light green
else if (i < 26) { pixels.setPixelColor(i, pixels.gamma32(pixels.Color(235, 215, 0)));} //Yellow
else if (i < 29) { pixels.setPixelColor(i, pixels.gamma32(pixels.Color(251, 109, 1)));} //Orange
else if (i < 32) { pixels.setPixelColor(i, pixels.gamma32(pixels.Color(255, 0, 0)));} //Red
//switch off the other pixels
int k;
for (k = numLedsToLight; k < pixels.numPixels(); k++) {
pixels.setPixelColor(k, pixels.gamma32(pixels.Color(0, 0, 0))); // assign color, using gamma curve for a more natural look
}
}
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
}
There is a problem with this circuit:
-
when is quiet , I have lit 4 led on the ring
-
on the maximum sound input, i have 10 led lit (no more, no matter what) The mapping from 0 ...1023 to 0 to max number of LED is done, but ...is not working as I wanted
Do I need a resistor or capacitor connected? -
If I make the circuit to work right, then I would like to have input from a 3.5 audio jack . What resistors, capacitors I would need in that case?
Thanks for help