Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
jack
Published

NeonDancer 9000

This incredible lamp will listen and dance to your music!

BeginnerShowcase (no instructions)299
NeonDancer 9000

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
Alligator Clips
Alligator Clips
×1
Battery Holder, 3 x AAA
Battery Holder, 3 x AAA
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

NeonDancer 9000

Code

NeonDancer 9000

Arduino
// ------  The NeonDancer 9000  ------- 

// This code will make your Adafruit Circuit Playground Express into a music visualizer, to an extent --- the mic isn't the best :(
// It cycles through random colors and LEDs very quickly to create a strobelight effect with color!! WOOOOOOOHHH
// It detects noise with the internal mic and depending on input it increases the brightness of the LEDs and how many will light up

// Created by Jhon Vergara


#include <Adafruit_CircuitPlayground.h>

#define Inputz  A1 // Our input for the switch


uint32_t colors[] =   // Colors to cycle through
{
  0xcc0000, // red  
  0xff9600, // orange
  0xffff00, // yellow
  0x00ff00, // green
  0x00ff81, // teal
  0x0000ff, // blue
  0x0000ff, // moar blue!
  0x9300ff, // purple
  0xff00ff, // pink
  0xcc0000  // red  
};

 int waitz;        // ----- How long to wait before the next cycle of lights begins
 int randz;        // ----- A random number to pick which LED will light up
 float brightz;    // ----- Takes microphone input to measure the amount of brightness and number of LEDs to light up
 float voltage;    // ----- Takes input from Inputz to turn into a more workable number to check if the lamp is "ON" or "OFF"
 
void setup() 
{
  CircuitPlayground.begin();
  waitz = 50;
}


// ----- This loop will check if the lamp is ON, execute the appropriate program and repeat FOREVER!!!
void loop() 

{
  {
// This looks useless but the "i" int is used in the inner "for loop" to change the color so a new color will be chosen per cycle
    for(int i = 0; i < 10; i += 1) 
    {    
      
 // ------  Check for input from switch  -----         
      uint16_t value = analogRead(Inputz);
      voltage = value * (5.0 / 1023.0);
      Serial.println(voltage);   

  // -----  Is the switch "ON"? If so run the program  -----
      if (voltage > 0.20)
      {      
         for(int j = 0; j < 10; j += 1)
         {         
         Soundz ();
         CircuitPlayground.setPixelColor(randz, colors[i]); //
         }
         CircuitPlayground.clearPixels(); 
      }
      
  // -----  If the switch is "OFF" clear the pixels  -----   
      else 
      {CircuitPlayground.clearPixels();}
      
    }  

// -----  Repeat the process after a brief wait  -----   
  delay(waitz);
  }
}


void Soundz ()
{
// ------  Gets input from the microphone and turns those weak values into more reasonable and workable numbers
  float sample = CircuitPlayground.mic.soundPressureLevel(10);  
  float brightz = (((sample - 63) * 10) -9);
  
// ------ bightz can't be a negative number or it won't work properly 
  if (brightz < 0)
  {
    brightz = 0;
  }
  
// -----  These "if statements" check the brightz variable to pick an appropriate amount of LEDS to light up
// -----  The higher the brightz value the more LEDS will light up and the brighter they will be

  if (brightz > 125.00)
  {randz = random(0, 10);}
  
  else if (brightz > 100.00)
  {randz = random(1, 9);}
  
  else if (brightz > 50.00)
  {randz = random(2, 8);}
  
  else if (brightz > 25.00) 
  {randz = random(3, 7);}
  
  else 
  {randz = random(4, 6);}

// ------  Sets the brightness of the LEDS based on the brightz float
  CircuitPlayground.setBrightness(brightz);
  
// ------  Check important information in the Serial Monitor
    Serial.println("SAMPLE----");
    Serial.println(sample);
    Serial.println("brightz-----");
    Serial.println(brightz);
    Serial.println("Randz-----");
    Serial.println(randz);
}

Credits

jack
4 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.