Light strips are awesome. In this project, we made a simple interface where we can change the values of each RGB LED on the strip. The FastLEd Arduino library is used to expand the compatibility of this project.


Download the RGB LED strip project.

Basic code behind this project



Complete tutorial

Select a color with the color picker. Clicking on a pixel will set up this pixel to the selected color.
The main script allows you to set the number of LEDs you are using and the global luminosity. The User Hover toggle will automatically toggle the pixel when you mouse is hovering a pixel.

If you are using another Arduino board, you SDA and SCL pins might not be A4 and A5. Edit the Arduino code to make it work!

Unity

The goal is to send the command "SetPixel id r g b" to arduino. The first element (SetPixel) is the command read by the arduino. The others are the parameters, as value between 0 and 255. We use the color picker made by zloedi.
When a pixel is toggled, the method SetPixelColor()is sent.

 \\...
public void SetPixelColor(int pixel)
{
    int r= Mathf.Round(CUIColorPicker.Instance.Color.r*globalLuminosity);
    int g= Mathf.Round(CUIColorPicker.Instance.Color.g*globalLuminosity);
    int b= Mathf.Round(CUIColorPicker.Instance.Color.b*globalLuminosity);

    string colorString = r + " " + g + " " + b;
   // We compose the string containing the colors. The parameter globalLuminosity is used to dim the pixel color.

    UduinoManager.Instance.Write("pixels", "SetPixel " + pixel + " " + colorString ); // We sebd
}

Control the LEDs with Arduino

FastLED is compatible with many LED strip. Be sure to set the correct reference to the setup function. For this project I used the WS2812B RGB LED.

  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);

Then, we create the command "SetPixel" charged to split the arguments and changing the pixel value. The function uduino.next(); will go to the next parameter (separated with the space character).

Uduino uduino("pixels");

void setup() {
  // ...
  uduino.addCommand("SetPixel", SetPixel);
}

void SetPixel() {
  char *arg;
  arg = uduino.next();
  int led =  atoi(arg);

  arg = uduino.next();
  int g = atoi(arg);

  arg = uduino.next();
  int r = (int)atoi(arg);

  arg = uduino.next();
  int b = (int)atoi(arg);

   leds[led].setRGB(r,g,b);
   FastLED.show();
}
///...