RGB Strip Controller

Product: https://www.tindie.com/products/williambailes/plex-controller/
Product: PLEX Controller

This controller controls a RGB LED strip with different colours and patterns. the controller that came with the strip was only controlled by an IR remote control and was very small. The problem with the remote was that it was easily lost and then the LED strip could not be controlled. With the controller that I have made it do much of what the IR controller can do and lots more.
The new controller will be able to be controlled by the IR remote as well as the normal interface it has. The controller has a LCD on it to see the function or mod it is on or going to be selected. The 3 buttons are used to scroll or select mods and functions.
The controller uses the PLEX board with a LCD, buttons and MOSFETs for switching the RGB LED on the strip. The controller is using the Arduino bootload and PWM for the fading and changing of colours on the RGB LED strip.

Code for Project

GNU General Public License v3.0

//#include <EEPROM.h>
#include <LiquidCrystal.h>


byte saveR[3] = {255, 0, 0};
byte saveG[3] = {0, 255, 0};
byte saveB[3] = {0, 0, 255};

byte R = 0;
byte G = 0;
byte B = 0;
int DMX = 0;
int mode = 1;
int menu = 1;
int setting = 1;
int level = 1;
int changespeed = 1000;
int selectedcolor = 0;
unsigned long storgedtime;

int val; 
 int RledPin = 1;
 int GledPin = 11;
 int BledPin = 9;
 int buttonPin = 14;
 int encoder0PinA = 15;
 int encoder0PinB = 16;
 int encoder0PinALast = LOW;
 int n = LOW;

LiquidCrystal lcd(3, 4, 5, 6, 7, 8);

void setup() 
{
  lcd.begin(16, 2);
   pinMode (encoder0PinA,INPUT);
   pinMode (encoder0PinB,INPUT);
  pinMode(buttonPin, INPUT);
  
  LCDcon();
  runcolor();
}

void loop() 
{
  n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
     if (digitalRead(encoder0PinB) == LOW) {
       SelectOption(false);
     } else {
       SelectOption(true);
     }
   } 
   encoder0PinALast = n;

  if(digitalRead(buttonPin) == HIGH)
  {
    while(digitalRead(buttonPin) == HIGH){runcolor();}
    
    if(level == 1)
    {
      mode = menu;
      menu = 1;
      level = 2;
    }
    else if(mode == 4)
    {
      level++;
      if(level>4)
      {
        level = 1;
      }
    }
    else
    {
      level = 1;
    }
    
    //LCDcon();
  }
  
  runcolor();
}

void runcolor()
{
  switch (mode) {
    case 0:
      R = 0;
      B = 0;
      G = 0;
      break;
    case 1:
      if(storgedtime+30<millis())
      {
        storgedtime = millis();
        if(R+setting>255 || G+setting>255 || B+setting>255 || R+setting<0 || G+setting<0 || B+setting<0)
        {
          selectedcolor++;
        }
        if(selectedcolor>6)
        {
          selectedcolor = 0;
        }
        switch (selectedcolor) {
          case 0:
            B = B + setting;
            break;
          case 1:
            R = R - setting;
            break;
          case 2:
            G = G + setting;
            break;
          case 3:
            B = B - setting;
            break;
          case 4:
            R = R + setting;
            break;
          case 5:
            G = G - setting;
            break;
        }
      }
      break;
    case 2:
      if(storgedtime+setting<millis())
      {
        storgedtime = millis();
        R = saveR[selectedcolor];
        G = saveG[selectedcolor];
        B = saveB[selectedcolor];
        selectedcolor++;
        if(selectedcolor >= sizeof(saveB))
        { 
          selectedcolor = 0;
        }
      }
      break;
    case 5:
      
      break;
  }
  analogWrite(RledPin, R);
  analogWrite(GledPin, G);
  analogWrite(BledPin, B);
}

void SelectOption(bool incres)
{
  int var = -1;
  if(incres)
  {
    var = 1;
  }

  if(level == 1)
  {
    menu = menu + var;
    if(menu>5)
    {
      menu = 0;
    }
    else if(menu<0)
    {
      menu = 5;
    }
  }
  else if(level == 2 && (mode == 1||mode == 2))
  {
    setting = setting + var;
    if(setting>255)
    {
      setting = 255;
    }
    else if(setting<0)
    {
      setting = 0;
    }
  }
  else if(level == 2 && (mode == 3))
  {
    setting = setting + var;
    if(setting>=sizeof(saveR))
    {
      setting = 0;
    }
    else if(setting<0)
    {
      setting = sizeof(saveR)-1;
    }
  }
  else if(level == 2 && mode == 4)
  {
    R = R + var;
    if(R>255)
    {
      R = 255;
    }
    else if(R<0)
    {
      R = 0;
    }
  }
  else if(level == 3 && mode == 4)
  {
    G = G + var;
    if(G>255)
    {
      G = 255;
    }
    else if(G<0)
    {
      G = 0;
    }
  }
  else if(level == 4 && mode == 4)
  {
    B = B + var;
    if(B>255)
    {
      B = 255;
    }
    else if(B<0)
    {
      B = 0;
    }
  }
    
  //LCDcon();
}

void LCDcon()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  switch (menu) {
    case 0:
      lcd.print("OFF");
      break;
    case 1:
      lcd.print("Fade");
      break;
    case 2:
      lcd.print("Strobe");
      break;
    case 3:
      lcd.print("color");
      break;
    case 4:
      lcd.print("custom");
      break;
    case 5:
      lcd.print("DMX");
      break;
  }
    
  if(level > 1)
  {
    lcd.setCursor(0, 1);
    switch (mode) {
      case 1:
        lcd.print("Speed:");
        lcd.print(setting);
        break;
      case 2:
        lcd.print("Speed:");
        lcd.print(setting);
        break;
      case 3:
        switch (setting) {
          case 1:
            lcd.print("red");
            R = saveR[0];
            G = saveG[0];
            B = saveB[0];
            break;
          case 2:
            lcd.print("green");
            R = saveR[1];
            G = saveG[1];
            B = saveB[1];
            break;
          case 3:
            lcd.print("Blue");
            R = saveR[2];
            G = saveG[2];
            B = saveB[2];
            break;
        }
        break;
      case 4:
        lcd.print("R:");
        lcd.print(R);
        lcd.print("G:");
        lcd.print(G);
        lcd.print("B:");
        lcd.print(B);
        break;
      case 5:
        lcd.print(DMX);
        break;
    }
    lcd.print("                ");
  }
}

Latest Projects

Popular Projects