DougalPlummerorionplummer
Published © GPL3+

Boom Box

Building a Son, first Arduino project and reconnecting with a joy lost to time.

IntermediateWork in progress5,472
Boom Box

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
General Purpose Quad Op-Amp
Texas Instruments General Purpose Quad Op-Amp
×1
Resistor 10k ohm
Resistor 10k ohm
×18
Resistor 1k ohm
Resistor 1k ohm
×6
Resistor 100k ohm
Resistor 100k ohm
×4
Resistor 330 ohm
Resistor 330 ohm
×1
Multi-Turn Precision Potentiometer- 10k ohms (25 Turn)
Multi-Turn Precision Potentiometer- 10k ohms (25 Turn)
×4
WS2812 Neopixel string
×1

Software apps and online services

Proteus 8 Pro
Used to do the circuit diagrams and lay the circuit board
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Mill
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Circuit Board made from the circuit

Schematics

Boom box amplifier schematic

Grand designs bit in the end we only loaded a fraction of the circuit

Code

Orion_Box_290915.ino

C/C++
Our first go at programmings
/* LedStripRainbow: Example Arduino sketch that shows
 * how to make a moving rainbow pattern on an
 * Addressable RGB LED Strip from Pololu.
 *
 * To use this, you will need to plug an Addressable RGB LED
 * strip from Pololu into pin 12.  After uploading the sketch,
 * you should see a moving rainbow.
 */

#include <PololuLedStrip.h>


// Create an ledStrip object and specify the pin it will use.
PololuLedStrip<12> ledStrip;

// Create a buffer for holding the colors (3 bytes per color).
#define LED_COUNT 120
rgb_color colors[LED_COUNT];

#define LOG_OUT 1 // use the log output function
#define LIN_OUT 1
#define OCTAVE 1
#define FFT_N 32 // set to 256 point fft

#include <FFT.h> // include the library

int j = 0 ;
int jLoop = 0 ;
uint8_t k = 0 ;
int iMode = 0 ;
int iHue = 0 ;
int iLum = 0 ;
int z = 0 ;

void setup()
{
  pinMode(13, OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT); 

  Serial.begin(115200); // use the serial port

  DIDR0 = 0x1F; // 0x01 turn off the digital input for adc0
  randomSeed(analogRead(4));
}

// Converts a color from HSV to RGB.
// h is hue, as a number between 0 and 360.
// s is the saturation, as a number between 0 and 255.
// v is the value, as a number between 0 and 255.
rgb_color hsvToRgb(uint16_t h, uint8_t s, uint8_t v)
{
    uint8_t f = (h % 60) * 255 / 60;
    uint8_t p = (255 - s) * (uint16_t)v / 255;
    uint8_t q = (255 - f * (uint16_t)s / 255) * (uint16_t)v / 255;
    uint8_t t = (255 - (255 - f) * (uint16_t)s / 255) * (uint16_t)v / 255;
    uint8_t r = 0, g = 0, b = 0;
    switch((h / 60) % 6){
        case 0: r = v; g = t; b = p; break;
        case 1: r = q; g = v; b = p; break;
        case 2: r = p; g = v; b = t; break;
        case 3: r = p; g = q; b = v; break;
        case 4: r = t; g = p; b = v; break;
        case 5: r = v; g = p; b = q; break;
    }
    return (rgb_color){r, g, b};
}

void loop(){
  while(1){
    iMode =  analogRead(1)/4 ;
    // Update the colors.
//    uint16_t time = millis() >> 2;
    switch(iMode){
        case 0 ... 4 :  // test patern
            for(uint16_t i = 0; i < LED_COUNT; i++){
              byte x = (jLoop) - (i << 3);
              colors[i] = hsvToRgb((uint32_t)x * 359 / 256, 255, iMode*50+50);
            }
            delay(iMode*5);
        break;
        case 16 ... 31 :  // wave effect
            for(uint16_t i = 19 ; i > 0 ; i--){
              byte x = ( iMode - 221 ) * 16 ;
              colors[19-i] = colors[20-i];
              colors[20+i] = colors[19+i];
              colors[59-i] = colors[60-i];
              colors[60+i] = colors[59+i];
              colors[99-i] = colors[100-i];
              colors[100+i] = colors[99+i];
            }
            k = (analogRead(4)/4)  ;
            if ( k > 100 ){
              iLum = k ;
            }
            iLum-- ;
            colors[19] = hsvToRgb(analogRead(4)/4 , 255, iLum);
            colors[20] = hsvToRgb(analogRead(4)/4 , 255, iLum);
            colors[59] = hsvToRgb(analogRead(4)/4 , 255, iLum);
            colors[60] = hsvToRgb(analogRead(4)/4 , 255, iLum);
            colors[99] = hsvToRgb(analogRead(4)/4 , 255, iLum);
            colors[100] = hsvToRgb(analogRead(4)/4 , 255, iLum);
            delay(50);
        break;
        case 32 ... 47 :  // random effect
            for(uint16_t i = 0 ;  i < LED_COUNT ; i++){
              colors[random(LED_COUNT)] = hsvToRgb(analogRead(4)/4 , 255, 50);
            }
        break;        
        case 48 ... 63 :  // equaliser FFT display (first cut)
            for(int i = 0; i < LED_COUNT; i++){
              colors[i].red =0 ;
              colors[i].green =0 ;
              colors[i].blue =0 ;             
            }
            for (uint16_t i = 0 ; i < (FFT_N*2) ; i += 2) { // save 32 samples
              fft_input[i] = analogRead(4) ; // put real data into even bins
              fft_input[i+1] = 0; // set odd bins to 0
            }
            fft_window(); // window the data for better frequency response
            fft_reorder(); // reorder the data before doing the fft
            fft_run(); // process the data in the fft
            fft_mag_log(); // take the output of the fft
            fft_mag_lin(); // take the output of the fft
            
           // z = ( fft_log_out[i]/16 )            
//            for (byte i = 3 ; i < FFT_N/2 ; i++) {
            for (byte i = 0 ; i < 20 ; i++) {
              z = fft_log_out[3] / 3 ;
              if ( i < z ){
                colors[119-i].blue = 127 ;
              }
              z = fft_log_out[4] / 3 ;
              if ( i < z ){
//                colors[119-i].green = 127 ;
              }
              z = fft_log_out[5] / 3 ;
              if ( i < z ){
//                colors[119-i].red = 127 ;
              }
              z = fft_log_out[6] / 3 ;
              if ( i < z ){
                colors[80+i].blue = 127 ;
              }
              z = fft_log_out[7] / 3 ;
              if ( i < z ){
//                colors[80+i].green = 127 ;
              }
              z = fft_log_out[8] / 3 ;
              if ( i < z ){
//                colors[80+i].red = 127 ;
              }
              z = fft_log_out[9] / 3 ;
              if ( i < z ){
                colors[79-i].blue = 127 ;
              }
              z = fft_log_out[10] / 3 ;
              if ( i < z ){
//                colors[79-i].green = 127 ;
              }
              z = fft_log_out[11] / 3 ;
              if ( i < z ){
//                colors[79-i].red = 127 ;
              }
              z = fft_log_out[12] / 3 ;
              if ( i < z ){
                colors[40+i].blue = 127 ;
              }
              z = fft_log_out[13] / 3 ;
              if ( i < z ){
//                colors[40+i].green = 127 ;
              }
              z = fft_log_out[14] / 3 ;
              if ( i < z ){
//                colors[40+i].red = 127 ;
              }
              z = fft_log_out[15] / 3 ;
              if ( i < z ){
                colors[39-i].blue = 127 ;
              }
              z = fft_log_out[16] / 3 ;
              if ( i < z ){
//                colors[39-i].green = 127 ;
              }
              z = fft_log_out[17] / 3 ;
              if ( i < z ){
//                colors[39-i].red = 127 ;
              }
              z = fft_log_out[18] / 3 ;
              if ( i < z ){
                colors[i].blue = 127 ;
              }
              z = fft_log_out[19] / 3 ;
              if ( i < z ){
//                colors[i].green = 127 ;
              }
              z = fft_log_out[21] / 3 ;
              if ( i < z ){
//                colors[i].red = 127 ;
              }
            }
            switch(jLoop/42){
              case 0:
                colors[19].red =255 ;
              break;
              case 1:
                colors[20].red =255 ;
              break;
              case 2:
                colors[59].red =255 ;
              break;
              case 3:
                colors[60].red =255 ;
              break;
              case 4:
                colors[99].red =255 ;
              break;
              case 5:
                colors[100].red =255 ;
              break;
            }
        break;        
        case 64 ... 79 :  // color bars
            for(uint16_t i = 0; i < 20; i++){
              int x = (((uint32_t)analogRead(4)/4 * 360 / 256 ) ) % 360 ;
              colors[i] = hsvToRgb(x , 255, 255);
              x = (((uint32_t)analogRead(4)/4 * 360 / 256 ) +(360/6 )) % 360 ;
              colors[i+20] = hsvToRgb(x , 255, 255);
              x = (((uint32_t)analogRead(4)/4 * 360 / 256 )+ (360/6*2 )) % 360 ;
              colors[i+40] = hsvToRgb(x , 255, 255);
              x = (((uint32_t)analogRead(4)/4 * 360 / 256 )+ (360/6*3 ) ) % 360 ;
              colors[i+60] = hsvToRgb(x , 255, 255);
              x = (((uint32_t)analogRead(4)/4 * 360 / 256 )+ (360/6*4 ) ) % 360 ;
              colors[i+80] = hsvToRgb(x , 255, 255);
              x = (((uint32_t)analogRead(4)/4 * 360 / 256 )+ (360/6*5 ) ) % 360 ;
              colors[i+100] = hsvToRgb(x , 255, 255);
            }
        break;
        case 80 ... 87 :  // color moving
            for(uint16_t i = 0; i < 20; i++){
              int x = (((uint32_t)analogRead(4)/4 * 360 / 256 ) + ((uint32_t)(i * 360 ) / 19  )) % 360 ;
              colors[i] = hsvToRgb(x , 255, 150);
              colors[39-i] = hsvToRgb(x , 255, 100);
              colors[i+40] = hsvToRgb(x , 255, 75);
              colors[79-i] = hsvToRgb(x , 255, 50);
              colors[i+80] = hsvToRgb(x , 255, 25);
              colors[119-i] = hsvToRgb(x , 255, 10);
            }
        break;
        case 88 ... 95 : // color moving 
            for(uint16_t i = 0; i < 20; i++){
              int x = (((uint32_t)jLoop * 360 / 256 ) + ((uint32_t)(i * 360 ) / 19  )) % 360 ;
              colors[i] = hsvToRgb(x , 255, 150);
              colors[39-i] = colors[i];
              colors[i+40] = colors[i];
              colors[79-i] = colors[i];
              colors[i+80] = colors[i];
              colors[119-i] = colors[i];
            }
        break;
        case 96 ... 111:  // god knows
            k = (analogRead(4)/4)  ;
            if ( k < 50 ){
              iHue++ ;
              if (iHue > 255){
                iHue = 0 ;
              }
            }
            if ( k > 100 ){
              iLum = k ;
            }
            iLum-- ;
            if ( iLum < 0 ){
              iLum = 0 ;
            }
            if ( k <  0 ){
              k = 0 ;
            }   
            colors[0] = hsvToRgb(iHue , 255, iLum );
            for(uint16_t i = 1 ; i < LED_COUNT ; i++){
              colors[i] = colors[0];
            }
        break;
        case 205 ... 220 :  // sparkles
            for(uint16_t i = 0; i < LED_COUNT; i++){
              colors[i].red =0 ;
              colors[i].green =0 ;
              colors[i].blue =0 ;             
            }
            k = (analogRead(4)/5)  ;  // should be 8 ????
            if ((k<120) && (k > 0) ) {
              colors[k] = hsvToRgb(jLoop , 255, 255);
            }
        break;
        case 221 ... 238 :   // solid color
            for(uint16_t i = 0; i < LED_COUNT; i++){
              byte x = ( iMode - 221 ) * 16 ;
              colors[i] = hsvToRgb((uint32_t)x , 255, 255);
            }
         break;   
        case 239 ... 256 :   // white light - work light
            for(uint16_t i = 0; i < LED_COUNT; i++){
              k = (( iMode - 238 ) * 15 )  ;
              colors[i].red = k ;
              colors[i].blue = k ;
              colors[i].green = k ;            
            }
         break;   
         default:
            Serial.print(jLoop) ; 
            Serial.println(" no Mode");
            for(uint16_t i = 0; i < LED_COUNT; i++){
              colors[i].red = 0 ;
              colors[i].blue = 0 ;
              colors[i].green = 0 ;            
            }
         break;
    }
    // Write the colors to the LED strip.
    ledStrip.write(colors, LED_COUNT);
    analogWrite(5, analogRead(4)/4);  // speaker leds
    
    if ( jLoop > 127 ){   // flash the built in Arduino board
      digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
    }else{              // wait for a second
      digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
    }             // wait for a second
    if ( jLoop > 255 ){
      jLoop=0 ;
    }  
    jLoop++ ;
  }
}

Credits

DougalPlummer

DougalPlummer

14 projects • 90 followers
I write code for a living, on everything from PLC's to web and accounting systems. I'm also very talented at farming prickles :)
orionplummer

orionplummer

0 projects • 8 followers
Thanks to Jim Andrews.

Comments