public void SetLedStrip(double res) { byte brightnes = currentBrightnes; var bla = (brightnes + (res)); if (bla < 0) { bla = 0; } else if (bla > 255) { bla = 255; } //Console.Out.WriteLine($"LED Difference: {(byte)(res)}"); Console.Out.WriteLine($"LED new Brightnes: {bla}"); byte size = 16; byte[] r = new byte[size]; byte[] g = new byte[size]; byte[] b = new byte[size]; var brightnesValueAsByte = (byte)bla; currentBrightnes = brightnesValueAsByte; for (int i = 0; i < size; i++) { r[i] = brightnesValueAsByte; g[i] = brightnesValueAsByte; b[i] = brightnesValueAsByte; } for (int i = 0; i < 4; i++) { ledStrip.SetRGBValues(i * (byte)16, 16, r, g, b); } }
private static string UID = "XYZ"; // Change XYZ to the UID of your LED Strip Bricklet #endregion Fields #region Methods // Use frame rendered callback to move the active LED every frame static void FrameRenderedCB(BrickletLEDStrip sender, int length) { b[rIndex] = 0; if(rIndex == NUM_LEDS-1) { rIndex = 0; } else { rIndex++; } b[rIndex] = 255; // Set new data for next render cycle sender.SetRGBValues(0, NUM_LEDS, r, g, b); }
// Use frame rendered callback to move the active LED every frame static void FrameRenderedCB(BrickletLEDStrip sender, int length) { b[rIndex] = 0; if (rIndex == NUM_LEDS - 1) { rIndex = 0; } else { rIndex++; } b[rIndex] = 255; // Set new data for next render cycle sender.SetRGBValues(0, NUM_LEDS, r, g, b); }
private static string UID = "XYZ"; // Change XYZ to the UID of your LED Strip Bricklet static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLEDStrip ls = new BrickletLEDStrip(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Set first 10 LEDs to green ls.SetRGBValues(0, 10, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0 }, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your LED Strip Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLEDStrip ls = new BrickletLEDStrip(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Set first 10 LEDs to green byte[] r = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; byte[] g = new byte[] {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0}; byte[] b = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0}; ls.SetRGBValues(0, 10, r, g, b); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLEDStrip ls = new BrickletLEDStrip(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 rendered callback to function FrameRenderedCB ls.FrameRenderedCallback += FrameRenderedCB; // Set initial rgb values to get started ls.SetRGBValues(0, NUM_LEDS, r, g, b); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLEDStrip ls = new BrickletLEDStrip(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 rendered callback to function FrameRenderedCB ls.FrameRendered += FrameRenderedCB; // Set initial rgb values to get started ls.SetRGBValues(0, NUM_LEDS, r, g, b); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private void WritePlayfield() { if (!okay) { return; } byte[][] field = DeepCopy(playfield); AddScoreToPlayfield(field); AddPaddlesToPlayfield(field); AddBallToPlayfield(field); // Reorder LED data into R, G and B channel byte[] r = new byte[Config.LED_ROWS * Config.LED_COLS]; byte[] g = new byte[Config.LED_ROWS * Config.LED_COLS]; byte[] b = new byte[Config.LED_ROWS * Config.LED_COLS]; for (int row = 0, i = 0; row < Config.LED_ROWS; ++row) { int colBegin; int colEnd; int colStep; if (row % 2 == 0) { colBegin = Config.LED_COLS - 1; colEnd = -1; colStep = -1; } else { colBegin = 0; colEnd = Config.LED_COLS; colStep = 1; } for (int col = colBegin; col != colEnd; col += colStep, ++i) { r[i] = COLORS[field[row][col]][Config.R_INDEX]; g[i] = COLORS[field[row][col]][Config.G_INDEX]; b[i] = COLORS[field[row][col]][Config.B_INDEX]; } } // Make chunks of size 16 byte[] rChunk = new byte[CHUNK_SIZE]; byte[] gChunk = new byte[CHUNK_SIZE]; byte[] bChunk = new byte[CHUNK_SIZE]; for (int i = 0; i < Config.LED_ROWS * Config.LED_COLS; i += CHUNK_SIZE) { byte k; for (k = 0; k < CHUNK_SIZE && i + k < Config.LED_ROWS * Config.LED_COLS; ++k) { rChunk[k] = r[i + k]; gChunk[k] = g[i + k]; bChunk[k] = b[i + k]; } try { ledStrip.SetRGBValues(i, k, rChunk, gChunk, bChunk); } catch (TinkerforgeException) { break; } } }
private void WritePlayfield() { if (!okay) { return; } byte[][] field = DeepCopy(playfield); if (!gameOver) { AddTetrominoToField(field, tetrominoPosRow, tetrominoPosCol, tetrominoCurrent, tetrominoForm); } // Reorder LED data into R, G and B channel byte[] r = new byte[Config.LED_ROWS * Config.LED_COLS]; byte[] g = new byte[Config.LED_ROWS * Config.LED_COLS]; byte[] b = new byte[Config.LED_ROWS * Config.LED_COLS]; for (int row = FIELD_ROWS - 2, i = 0; row > 2; --row) { int colBegin; int colEnd; int colStep; if (row % 2 == 0) { colBegin = FIELD_COLS - 2; colEnd = 0; colStep = -1; } else { colBegin = 1; colEnd = FIELD_COLS - 1; colStep = 1; } for (int col = colBegin; col != colEnd; col += colStep, ++i) { r[i] = COLORS[field[row][col]][Config.R_INDEX]; g[i] = COLORS[field[row][col]][Config.G_INDEX]; b[i] = COLORS[field[row][col]][Config.B_INDEX]; } } // Make chunks of size 16 byte[] rChunk = new byte[CHUNK_SIZE]; byte[] gChunk = new byte[CHUNK_SIZE]; byte[] bChunk = new byte[CHUNK_SIZE]; for (int i = 0; i < Config.LED_ROWS * Config.LED_COLS; i += CHUNK_SIZE) { byte k; for (k = 0; k < CHUNK_SIZE && i + k < Config.LED_ROWS * Config.LED_COLS; ++k) { rChunk[k] = r[i + k]; gChunk[k] = g[i + k]; bChunk[k] = b[i + k]; } try { ledStrip.SetRGBValues(i, k, rChunk, gChunk, bChunk); } catch (TinkerforgeException) { break; } } }