Paolo
Published

Sound visualizer and Adjuster

Project that visualizes sound on a led strip with a sound sensor and adjusts volume of a knob with a servo.

BeginnerShowcase (no instructions)5 hours32
Sound visualizer and Adjuster

Things used in this project

Hardware components

SparkFun Sound Detector (with Headers)
SparkFun Sound Detector (with Headers)
×1
Rotary Potentiometer, 10 kohm
Rotary Potentiometer, 10 kohm
×1
Photon 2
Particle Photon 2
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Circut

Code

Untitled file

C/C++
#include <neopixel.h>
#ifdef AVR
#include <avr/power.h>
#endif
SYSTEM_MODE(AUTOMATIC);
SerialLogHandler logHandler(LOG_LEVEL_INFO); // penis 1 

Servo myServo;

int analogPin = A5;      // penis 2
int val = 0;            // penis 3

int outputValue=0;
int rememberOutputValue;
int randNumber;
int counter = 0;
int loopCounter = 0;

#if (PLATFORM_ID == 32)

#define PIXEL_PIN SPI1
#else 
#define PIXEL_PIN 2
#endif
#define PIXEL_COUNT 80
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void setup() {
  pixels.begin();
  randomSeed(analogRead(A5));
  Serial.begin(9600);
  
  myServo.attach(1);    // penis 4

}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
  }
  WheelPos -= 170;
  return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
}


void loop() {
    val = analogRead(analogPin);
    val = map(val, 0, 4095, 10, 170);

    myServo.write(val); 

   int sensorValue; 
   counter = 0;
   
   sensorValue = analogRead(A0);
   sensorValue = map(sensorValue, 0, 4095, 0, 3000);
   
   

   for (int i= 56; i < 156; i++){
    //sensorValue = analogRead(A0);
    if(sensorValue > 156) counter++;
   }


  if(map(counter, 10, 60, 80, 80) > outputValue)outputValue = map(counter, 00, 40, 0, 40);
  else if(loopCounter %2 == 0)outputValue-=1;

  if(outputValue < 0) outputValue = 0;
  if(outputValue > 60) outputValue = 60;


  if(loopCounter % 100 == 0)randNumber = random(255);
  loopCounter++;

 for(int i=0;i < PIXEL_COUNT;i++){

    pixels.setPixelColor(i, pixels.Color(0,0,0, 255)); 

  }
  
 if(rememberOutputValue != outputValue){    
  for(int i=60;i > (60-outputValue) || (outputValue == 20 && i == 0);i--){
  pixels.setPixelColor(i, Wheel((randNumber) & 255));
 }

   pixels.show(); 
}   
   rememberOutputValue = outputValue;
}

Credits

Paolo
1 project • 0 followers
Thanks to Adafruit .

Comments