Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            Client     client = new Client("127.0.0.1", 7890, true, true);
            PixelStrip pixels = new PixelStrip(30);

            while (true)
            {
                //rainbow effect
                for (int i = 0; i <= 360; i = i + 5)
                {
                    var color = new HSLColor(hue: i, saturation: 100, luminosity: 100);
                    pixels.AddFirst(color.ToRgbPixel());
                    client.putPixels(pixels);
                    Thread.Sleep(100);
                }
            }
        }
Ejemplo n.º 2
0
        public void putPixels(PixelStrip pixels, int channel = 0)
        {
            debug("put pixes: connecting");
            bool is_connected = ensureConnected();

            if (!is_connected)
            {
                debug("Put pixels not connected. Ignoring these pixels.");
            }

            int len_hi_byte  = pixels.Count * 3 / 256;
            int len_low_byte = (pixels.Count * 3) % 256;

            List <byte> pieces = new List <byte>
            {
                Convert.ToByte(channel),
                Convert.ToByte(0),
                Convert.ToByte(len_hi_byte),
                Convert.ToByte(len_low_byte)
            };

            foreach (var item in pixels)
            {
                pieces.Add(item.r);
                pieces.Add(item.g);
                pieces.Add(item.b);
            }

            byte[] message = new byte[pieces.Count];

            for (int i = 0; i < pieces.Count; i++)
            {
                message[i] = pieces[i];
            }


            _socket.Send(message);
            _socket.Send(message);
        }