Components and supplies
General Purpose Dual Op-Amp
Resistor 10k ohm
Resistor 1M ohm
Breadboard (generic)
MSGEQ7
Resistor 100k ohm
WS2812B Addressable LED with Heat Sink
Capacitor 100 nF
Arduino Leonardo
Capacitor 1 µF
Project description
Code
Code snippet #1
arduino
1/*Arduino Audio Blink 2The WS2812 LEDs will blink in base of your voice! Try it and have fun! 3Author: Arturo Guadalupi <a.guadalupi@arduino.cc>*/ 4#include <Adafruit_NeoPixel.h> 5const int msg7RESET = 2; 6const int msg7Strobe = 4; 7const int msg7DCout = A0; 8const int PIN = 3; 9const int NUMPIXELS = 15; //number of LEDs 10int spectrumRead[7] = {0}; //variable uded to store the analog values from the MSGEQ7 11int i; //variable used as index in the sketch 12// Parameter 1 = number of pixels in strip 13// Parameter 2 = Arduino pin number (most are valid) 14// Parameter 3 = pixel type flags, add together as needed: 15// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) 16// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) 17// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) 18// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) 19Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800); 20void setup() { 21 strip.begin(); 22 strip.show(); // Initialize all pixels to 'off' 23 //Pins used to drive the MSGEQ7 24 pinMode(msg7RESET, OUTPUT); 25 pinMode(msg7Strobe, OUTPUT); 26} 27void loop() { 28 readMSGEQ7(); //read bands value 29 // R G B DELAY 30 colorWipe(strip.Color(map(spectrumRead[2], 0, 1023, 0, 100), 0, 0), map(spectrumRead[2], 0, 1023, 0, 3)); 31 // R G B DELAY 32 colorWipe(strip.Color(0, 0, map(spectrumRead[3], 0, 1023, 0, 100)), map(spectrumRead[3], 0, 1023, 0, 3)); 33} 34//Code used to get the analog values from the MSGEQ7. See datasheet for further informations 35void readMSGEQ7() 36{ 37 digitalWrite(msg7RESET, HIGH); // reset the MSGEQ7's counter 38 delay(5); 39 digitalWrite(msg7RESET, LOW); 40 for (i = 0; i < 7; i++) { 41 digitalWrite(msg7Strobe, LOW); // output each DC value for each freq band 42 delayMicroseconds(35); // to allow the output to settle 43 spectrumRead[i] = analogRead(msg7DCout); 44 digitalWrite(msg7Strobe, HIGH); 45 } 46} 47// Fill the dots one after the other with a color 48void colorWipe(uint32_t c, uint8_t wait) { 49 for (uint16_t i = 0; i < strip.numPixels(); i++) { 50 strip.setPixelColor(i, c); 51 strip.show(); 52 } 53 delay(wait); 54}
Code snippet #1
arduino
1/*Arduino Audio Blink 2The WS2812 LEDs will blink in base of your voice! Try it and have fun! 3Author: Arturo Guadalupi <a.guadalupi@arduino.cc>*/ 4#include <Adafruit_NeoPixel.h> 5const int msg7RESET = 2; 6const int msg7Strobe = 4; 7const int msg7DCout = A0; 8const int PIN = 3; 9const int NUMPIXELS = 15; //number of LEDs 10int spectrumRead[7] = {0}; //variable uded to store the analog values from the MSGEQ7 11int i; //variable used as index in the sketch 12// Parameter 1 = number of pixels in strip 13// Parameter 2 = Arduino pin number (most are valid) 14// Parameter 3 = pixel type flags, add together as needed: 15// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) 16// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) 17// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) 18// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) 19Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800); 20void setup() { 21 strip.begin(); 22 strip.show(); // Initialize all pixels to 'off' 23 //Pins used to drive the MSGEQ7 24 pinMode(msg7RESET, OUTPUT); 25 pinMode(msg7Strobe, OUTPUT); 26} 27void loop() { 28 readMSGEQ7(); //read bands value 29 // R G B DELAY 30 colorWipe(strip.Color(map(spectrumRead[2], 0, 1023, 0, 100), 0, 0), map(spectrumRead[2], 0, 1023, 0, 3)); 31 // R G B DELAY 32 colorWipe(strip.Color(0, 0, map(spectrumRead[3], 0, 1023, 0, 100)), map(spectrumRead[3], 0, 1023, 0, 3)); 33} 34//Code used to get the analog values from the MSGEQ7. See datasheet for further informations 35void readMSGEQ7() 36{ 37 digitalWrite(msg7RESET, HIGH); // reset the MSGEQ7's counter 38 delay(5); 39 digitalWrite(msg7RESET, LOW); 40 for (i = 0; i < 7; i++) { 41 digitalWrite(msg7Strobe, LOW); // output each DC value for each freq band 42 delayMicroseconds(35); // to allow the output to settle 43 spectrumRead[i] = analogRead(msg7DCout); 44 digitalWrite(msg7Strobe, HIGH); 45 } 46} 47// Fill the dots one after the other with a color 48void colorWipe(uint32_t c, uint8_t wait) { 49 for (uint16_t i = 0; i < strip.numPixels(); i++) { 50 strip.setPixelColor(i, c); 51 strip.show(); 52 } 53 delay(wait); 54}
Downloadable files
Schematic #1
Schematic #1
Comments
Only logged in users can leave comments
Arduino_Scuola
0 Followers
•0 Projects
Table of contents
Intro
0
0