public Pong(IPConnection ipcon) { for (int row = 0; row < Config.LED_ROWS; ++row) { playfield[row] = new byte[Config.LED_COLS]; } // Call a getter to check that the Bricklet is avialable ledStrip = new BrickletLEDStrip(Config.UID_LED_STRIP_BRICKLET, ipcon); try { ledStrip.GetFrameDuration(); System.Console.WriteLine("Found: LED Strip ({0})", Config.UID_LED_STRIP_BRICKLET); } catch (TinkerforgeException) { System.Console.WriteLine("Not Found: LED Strip ({0})", Config.UID_LED_STRIP_BRICKLET); return; } keyPress = new KeyPress(ipcon); speaker = new PongSpeaker(ipcon); okay = true; ledStrip.SetFrameDuration(40); ledStrip.FrameRendered += FrameRenderedCB; InitGame(); }
private static void Main() { double setPoint = 130; IPConnection ipcon = new IPConnection(); // Create IP connection ipcon.Connect(HOST, PORT); // Connect to brickd var light = new BrickletAmbientLight(UidAmbientLight, ipcon); ledStrip = new BrickletLEDStrip(UidLedStrip, ipcon); var pid = new PidCompute(0.3, 0.00001, 0); ledStrip.SetChannelMapping(6); var ledHandler = new LedHanlder(ledStrip); while (true) { var lux = light.GetIlluminance(); Console.Out.WriteLine($"Lux: {lux}"); var res = pid.Compute(setPoint, lux); Console.Out.WriteLine($"PID Result: {res}"); ledHandler.SetLedStrip(res); Thread.Sleep(20); } Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static void Main() { double setPoint = 400; IPConnection ipcon = new IPConnection(); // Create IP connection ipcon.Connect(HOST, PORT); // Connect to brickd var display = new BrickletLCD20x4(UidLcdDisplay, ipcon); var displayPID = new BrickletLCD20x4(UidLcdDisplayPID, ipcon); var light = new BrickletAmbientLight(UidAmbientLight, ipcon); ledStrip = new BrickletLEDStrip(UidLedStrip, ipcon); var pid = new PidCompute(0.3, 0.0001, 0.0000003); ledStrip.SetChannelMapping(6); var rotaryPotiP = new BrickletRotaryPoti(UiWheelP, ipcon); var rotaryPotiI = new BrickletRotaryPoti(UiWheelI, ipcon); var rotaryPotiD = new BrickletRotaryPoti(UiWheelD, ipcon); var linerPoti = new BrickletLinearPoti("bxu", ipcon); display.BacklightOn(); displayPID.BacklightOn(); var ledHandler = new LedHanlder(ledStrip); double P = 0.15; double I = 0.15; double D = 0.15; while (true) { P = rotaryPotiP.GetAnalogValue() / 100000.0; I = rotaryPotiI.GetAnalogValue() / 1000000.0; D = rotaryPotiD.GetAnalogValue() / 1000000.0; setPoint = linerPoti.GetAnalogValue() / 10; pid = new PidCompute(P, I, D); Console.WriteLine("Goal: " + setPoint); var lux = light.GetIlluminance(); Console.Out.WriteLine($"Lux: {lux}"); var res = 0.1 * pid.Compute(setPoint, lux); Console.Out.WriteLine($"PID Result: {res}"); ledHandler.SetLedStrip(res); display.ClearDisplay(); displayPID.ClearDisplay(); display.WriteLine(0, 0, $"Setpoint: {setPoint}"); display.WriteLine(1, 0, $"Lux: {lux}"); display.WriteLine(2, 0, $"PID Result: {res}"); displayPID.WriteLine(0, 0, $"P: {P}"); displayPID.WriteLine(1, 0, $"I: {I}"); displayPID.WriteLine(2, 0, $"D: {D}"); Thread.Sleep(10); } 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 // 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(); }
public LedHanlder(BrickletLEDStrip ledStrip) { this.ledStrip = ledStrip; currentBrightnes = 100; }
private void FrameRenderedCB(BrickletLEDStrip sender, int length) { WritePlayfield(); }