smvasudevan768
Published © GPL3+

LED strip color mixer with OLED display

Create a simple color mixer which can display up to 16 million colors!

BeginnerFull instructions provided585
LED strip color mixer with OLED display

Things used in this project

Hardware components

Analog joystick (Generic)
A thumb joystick is recommended
×1
Adafruit Neopixel RGB
×1
Jumper wires (generic)
Jumper wires (generic)
Mostly male-to-male if you are going to use a breadboard. 3 female-to male wires required to connect LED strip
×18
128x32 pixel OLED
0.91 inch screen. You can edit the code in case you have a 128x64 OLED.
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
You can use a smaller size if you'd like. I prefer the larger size.
×1
Custom PCB
Custom PCB
(Optional)
×1
Wire (Optional)
Generic wire if you are going to use a PCB.
×1
Arduino UNO
Arduino UNO
Preferred over MEGA and Nano
×1
Buttons (Optional)
If you want to customize it further
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
(Optional)

Story

Read more

Schematics

Schematic Diagram

Code

LEDstrip

Arduino
#include <Adafruit_NeoPixel.h>
#define LED_PIN    6
#define LED_COUNT 30
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
#define joyX A2
#define joyY A1
#include "U8glib.h" 

U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); //Initialize OLED display


int r = 0; 

int g = 0;

int b = 0;//These three variables determine RGB values

int num = 1; //This variable helps switch between colors.

const int swpin = 5; //Defining switch button pin
 
int SW = 0;

void draw()
{
//READINGS-------------------------------------------------------------------
  int X;
  int Y;
  int Xval;
  int Yval;
  
  
  
  X = analogRead(joyX); //Reading off of VRx
  Y = analogRead(joyY); //Reading off of VRy

  Xval = map(X, 0, 1023, 10, 0); 
  Yval = map(Y, 0, 1023, 255, 0); //mapping values 

//COLOR SWITCHING-------------------------------------------------------------
  if(Xval < 9){   //This bit of code helps us switch between R, G and B.
    num = num + 1; 
    }
  if(Xval > 1){
    num = num - 1;
    }                  

//LIMITS-------------------------------------------------------------------
  if(num > 3){ //This bit creates a cycle between colors
    num = 1;    
  }
  if(num < 1){
    num = 3;
  }


//Red-value-------------------------------------------------------------------------------------------------------
char buf[8]; //Define buffer

if(r < 0){
  r = 255;
}
                   //Cycles red value
  if(r > 255){
  r = 0;
 }
 
//Write text. (x, y, text) 
u8g.drawStr(1, 16, "R-");
u8g.drawStr(20, 16, itoa(r, buf, 10)); //itoa(int1, buffer, int2) converts int1(base int2) to ASCII format. Buffer stores this data.
 
//Green-value-----------------------------------------------------------------------------------------------------


if(g < 0){
  g = 255;
}
              //Cycles green value
  if(g > 255){
  g = 0;
 }


u8g.drawStr(64, 16, "G-");
u8g.drawStr(84, 16, itoa(g, buf, 10));

//Blue-value------------------------------------------------------------------------------------------------------


if(b < 0){
  b = 255;
}
               //Cycles blue value
if (b > 255){
  b = 0;
}

u8g.drawStr(1, 32, "B-");
u8g.drawStr(20, 32, itoa(b, buf, 10));

//LINE (x1, y1, x2, y2)-------------------------------------------------------------------------------------------
u8g.drawLine(1, 17, 128, 17);
//draw a line (x1, y1, x2, y2)

//SET COLOR------------------------------------------------------------------------------------------------------------
u8g.drawStr(64, 32, "Color-");

  switch(num) {
    /*This function only converts the num values to R, G and B strings according to the current color being edited.
      This code makes sure that when editing value intensity, the 'Color' field actually switches to the correct color(R, G or B).*/

    case 1  :
        u8g.drawStr(115, 32, "R");
          if(Yval > 230){
              r = r+1;
          } 

          if(Yval < 20){
              r = r-1;
          } 
        break;
  
    case 2  :
        u8g.drawStr(115, 32, "G");
          if(Yval > 230){
             g = g+1;
            } 

          if(Yval < 20){
             g = g-1;
            } 
        break;
      
    case 3  :
        u8g.drawStr(115, 32, "B");
          if(Yval > 230){
             b = b+1;
              } 
            
              if(Yval < 20){
              b = b-1;
              } 
        break;  
  }
}

void setup() {
  u8g.setFont(u8g_font_unifont); //Set text font
  pinMode(swpin, INPUT_PULLUP); //Define the pin mode for the switch button
  strip.begin();   //Initiate LED strip       
  strip.show();    //Update Strip
  strip.setBrightness(50); //Set the brightness of each NeoPixel
}


void loop() {
  u8g.firstPage();
  do {draw();
  } while (u8g.nextPage()); //Draw loop (OLED)
  delay(10); //Delay before each loop begins
  if(SW < 1){ //Ensures that the strip stays on at all times; you can use the int SW and link it to input swpin to assign to it a different function.
     colorWipe(strip.Color(r,   g,   b), 5);//The variables r g and b are linked to the values you will see on the OLED. The number '5' defines the number of seconds it takes to fill up the entire strip (Neopixels turn on one at a time in this function). 
    }
  
}
void colorWipe(uint32_t color, int wait) { //Defining a new function to display the color. 
  for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip:
    strip.setPixelColor(i, color);         //  Set pixel's color 
    strip.show();                          //  Update strip to match
    delay(wait);                           //  Pause for a moment
  }
 }

  

Credits

smvasudevan768

smvasudevan768

2 projects • 0 followers

Comments