public void init(int height, int width) { mHeight = height; mWidth = width; ipcon = new IPConnection(); // Create IP connection ls = new BrickletLEDStripV2(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd ls.SetChipType(BrickletLEDStripV2.CHIP_TYPE_WS2812); ls.SetChannelMapping(BrickletLEDStripV2.CHANNEL_MAPPING_GRB); // Set frame duration to 50ms (20 frames per second) ls.SetFrameDuration(50); // Register frame started callback to function FrameStartedCB ls.FrameStartedCallback += FrameStartedCB; int pixelNumber = mHeight * mWidth; // alles aus byte[] pixelPuffer = new byte[pixelNumber * 3]; for (int i = 0; i < pixelPuffer.Length; i++) { pixelPuffer[i] = 0; } ls.SetLEDValues(0, pixelPuffer); }
private static string UID = "XYZ"; // Change XYZ to the UID of your LED Strip Bricklet 2.0 static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLEDStripV2 ls = new BrickletLEDStripV2(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Set first 3 LEDs to red, green and blue ls.SetLEDValues(0, new byte[] { 255, 0, 0, 0, 255, 0, 0, 0, 255 }); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLEDStripV2 ls = new BrickletLEDStripV2(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Set frame duration to 50ms (20 frames per second) ls.SetFrameDuration(50); // Register frame started callback to function FrameStartedCB ls.FrameStartedCallback += FrameStartedCB; Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
// Use frame started callback to move the active LED every frame static void FrameStartedCB(BrickletLEDStripV2 sender, int length) { if (TinkerforgeDisplay.nextScreen != null) { byte[] pixelPuffer = new byte[length]; for (int i = 0; i < length; i = i + 3) { Byte col = findPixelInScreen(i / 3, TinkerforgeDisplay.nextScreen); try { switch (col) { case 0: // BLACK pixelPuffer[i] = 0; pixelPuffer[i + 1] = 0; pixelPuffer[i + 2] = 0; break; case 1: // RED pixelPuffer[i] = 10; pixelPuffer[i + 1] = 0; pixelPuffer[i + 2] = 0; break; case 2: // GREEN pixelPuffer[i] = 0; pixelPuffer[i + 1] = 10; pixelPuffer[i + 2] = 0; break; case 3: // BLUE pixelPuffer[i] = 0; pixelPuffer[i + 1] = 0; pixelPuffer[i + 2] = 10; break; case 4: // TÜRKIS pixelPuffer[i] = 0; pixelPuffer[i + 1] = 10; pixelPuffer[i + 2] = 10; break; case 5: // MAGENTA pixelPuffer[i] = 10; pixelPuffer[i + 1] = 0; pixelPuffer[i + 2] = 10; break; case 6: // WHITE pixelPuffer[i] = 5; pixelPuffer[i + 1] = 10; pixelPuffer[i + 2] = 5; break; case 7: // YELLOW pixelPuffer[i] = 5; pixelPuffer[i + 1] = 10; pixelPuffer[i + 2] = 0; break; } } catch (IndexOutOfRangeException) { // WARUM? } } sender.SetLEDValues(0, pixelPuffer); } }
private static string UID = "XYZ"; // Change XYZ to the UID of your LED Strip Bricklet 2.0 // Use frame started callback to move the active LED every frame static void FrameStartedCB(BrickletLEDStripV2 sender, int length) { Console.WriteLine("Length: " + length); }