Introduction: WS2801 Addressable LEDs Class [C#]

i have previously made a tutorial on how to have an ambilight around your screen with the ws2801 leds.

now we can control them using c# and arduino.

the same arduino uno code with the same connection from this instructable:

https://www.instructables.com/id/Extreme-Ambilight-System-using-DotStars-Led-ws2801/

after connecting the strip and downloading visual studio

download the rar file and let's start the dirty work :)

Step 1: C# Coding

start your windows forms project.

include the ws2801.cs class

this class helps you drive ws2801 addressable LEDs quickly via arduino using RGB colors or HUE of color.
one note is that if you are using the hues our spectrume goes from 0(red) to 255(also red but from the other end of the spectrum), you can check out the picture in the rar or visit FASTLED.IO to see a full mappnig of the colors in hue

these type of leds are controlled as a whole strip or by address, each led has an address starting from 0 and incrementing tell the end of the strip, also each has 3 bytes of color (RGB).
color code conversion was applied.

Using the class:

as any calss, make an instanse of of the WS2801 class giving it a com port of the arduino and the led count, also the baudrate, both baudrate and led count must match the arduino code
here's an example of two buttons, button1 to make led#0 white using RGB, also make led#3 blue using hue, then send the buffered colors to arduino

WS2801 screen;
public Form1() { screen = new WS2801(44, "COM30", 250000); InitializeComponent(); }
   private void button1_Click(object sender, EventArgs e)
   {
       screen.Set_individual_RGB(0, 255, 255, 255);
       screen.Set_individual_HUE(3, 170);
       screen.Send_Buffer();
   }
   private void button2_Click(object sender, EventArgs e)
   {
       screen.Clear();
   }

this class has 6 methods to write a color on the strip, each has it's advantage.
also the class is well documented so you won't have a problem using it. there's a nice method to fill a moving spectrum only requires a boolean to start or stop. the arduino code used is innitially made by adalight, modefied to become even faster using FASTLED.IO library.

Step 2: Points of Interest

using 250000 baudrate on usb with arduino uno wasn't the good idea at the beggning, but after trying it, worked like a charm.

also a good idea to control these leds is to implement a color picker. why would we want to control these leds ? well, i've made a c# program to analyze audio to simple spectrum values, which allowed me to detect the bass and send it to lot's of leds setup at my desktop as seen in the first video.

and here's another for the spectrum which is embedded in the class

Step 3: Combining Audio Spectrum With This Class

if you were able to use all the functions of this class you will be able to use this Instructable:

https://www.instructables.com/id/Audio-Spectrum-Software-C/

to get the spectrum data and send it to your ws2801 leds.

here's a sample of the timer code i used:

int j = 0;
for (i = 21; i >= 0; i--) { if (j < ((int)((((spectrum1.Bar02.Value + spectrum1.Bar03.Value) / 2) / 255.0) * 22))) { hueToRGB1((int)(160 - ((7.619047619047619) * (j))), 255); Set_Addressable_Screen(i, R1, G1, B1); }

else { Set_Addressable_Screen(i, 0, 0, 0); }

j++; }

that will control the led# 21 to the led 0 and will turn on along the the spectrum values.

the colors of those leds are in the range of 0 - 160 , 0 being red and 160 being blue in hues

the 7.619047619047619 number came from 160 devided by the address of the last led being 21

the 160 minus the rest is because we want to start from 160 and end with the 0 being the red.

last, in the making of this project i have bought the razer blackwidow chroma keyboard that contained addressable leds which was the perfect match for my setup, if you're interested in such a thing you can ask in the comments and i will gladly make a tutorial on how to use there .net library to do as such.

that's about all for this project, if you use it, make sure to link a video of your setup .. :)

Comments

About This Instructable

1,481views

10favorites

License:

Bio: Computer Engineering @ASU in JO.
Add instructable to: