Arduino_Scuola
Published © GPL3+

Audio Blink

This lessons aims to show how to make an Audio Blink.

IntermediateFull instructions provided19 minutes4,114
Audio Blink

Things used in this project

Hardware components

Arduino Leonardo
Arduino Leonardo
×1
Resistor 1M ohm
Resistor 1M ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 100k ohm
Resistor 100k ohm
×1
General Purpose Dual Op-Amp
Texas Instruments General Purpose Dual Op-Amp
×1
SparkFun MSGEQ7
×1
Breadboard (generic)
Breadboard (generic)
Or perfboard
×1
Capacitor 100 nF
Capacitor 100 nF
×1
Capacitor 1 µF
Capacitor 1 µF
×1
WS2812B Addressable LED with Heat Sink
×1

Story

Read more

Schematics

Schematic #1

Code

Code snippet #1

Arduino
/*Arduino Audio Blink
The WS2812 LEDs will blink in base of your voice! Try it and have fun!
Author: Arturo Guadalupi <a.guadalupi@arduino.cc>*/
#include <Adafruit_NeoPixel.h>
const int msg7RESET = 2;
const int msg7Strobe = 4;
const int msg7DCout = A0;
const int PIN = 3;
const int NUMPIXELS = 15; //number of LEDs
int spectrumRead[7] = {0}; //variable uded to store the analog values from the MSGEQ7
int i; //variable used as index in the sketch
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  //Pins used to drive the MSGEQ7
  pinMode(msg7RESET, OUTPUT);
  pinMode(msg7Strobe, OUTPUT);
}
void loop() {
  readMSGEQ7(); //read bands value
  //                    R                                      G  B   DELAY
  colorWipe(strip.Color(map(spectrumRead[2], 0, 1023, 0, 100), 0, 0), map(spectrumRead[2], 0, 1023, 0, 3));
  //                    R  G  B                                       DELAY
  colorWipe(strip.Color(0, 0, map(spectrumRead[3], 0, 1023, 0, 100)), map(spectrumRead[3], 0, 1023, 0, 3));
}
//Code used to get the analog values from the MSGEQ7. See datasheet for further informations
void readMSGEQ7()
{
  digitalWrite(msg7RESET, HIGH); // reset the MSGEQ7's counter
  delay(5);
  digitalWrite(msg7RESET, LOW);
  for (i = 0; i < 7; i++) {
    digitalWrite(msg7Strobe, LOW); // output each DC value for each freq band
    delayMicroseconds(35); // to allow the output to settle
    spectrumRead[i] = analogRead(msg7DCout);
    digitalWrite(msg7Strobe, HIGH);
  }
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
  }
  delay(wait);
}

Github

https://github.com/adafruit/Adafruit_NeoPixel

Credits

Arduino_Scuola

Arduino_Scuola

32 projects • 155 followers

Comments