public Component() { client = new HttpClient(); // Create connection object _ipConnection = new IPConnection(); // Create device objects _dualButtonBricklet = new BrickletDualButton(DualButtonUID, _ipConnection); _lcdBricklet = new BrickletLCD20x4(DisplayUID, _ipConnection); _temperatureBricklet = new BrickletTemperature(TemperatureUID, _ipConnection); _humidityBricklet = new BrickletHumidity(HumidityUID, _ipConnection); _linearPoti = new BrickletLinearPoti(LinearPotiUID, _ipConnection); _rgbButton = new BrickletRGBLEDButton(RGBButtonUID, _ipConnection); _rotaryPoti = new BrickletRotaryPoti(RotaryPotiUID, _ipConnection); _segmentDisplay = new BrickletSegmentDisplay4x7(SegmentUID, _ipConnection); _motionDetector = new BrickletMotionDetectorV2(motionDetectorUID, _ipConnection); _multiTouch = new BrickletMultiTouch(multiTouchUID, _ipConnection); //register listeners _dualButtonBricklet.StateChangedCallback += DualButtonStateChanged; //register callback _linearPoti.PositionCallback += PositionCb; _rotaryPoti.PositionCallback += PositionRCB; _motionDetector.MotionDetectedCallback += MotionDetectedCB; _motionDetector.DetectionCycleEndedCallback += DetectionCycleEndedCB; _multiTouch.TouchStateCallback += TouchStateCB; }
public void PositionRCB(BrickletRotaryPoti sender, short position) { Console.WriteLine("Position: " + position); _green = (byte)((GREEN + position) / 1.5); _rgbButton.SetColor(_red, _green, _blue); WriteDigits(_red + _green + _blue); }
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 Rotary Poti Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletRotaryPoti rp = new BrickletRotaryPoti(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current position (range is -150 to 150) short position = rp.GetPosition(); Console.WriteLine("Position: " + position); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Rotary Poti Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletRotaryPoti rp = new BrickletRotaryPoti(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Register position callback to function PositionCB rp.Position += PositionCB; // Set period for position callback to 0.05s (50ms) // Note: The position callback is only called every 0.05 seconds // if the position has changed since the last call! rp.SetPositionCallbackPeriod(50); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
// Callback function for position callback (parameter has range -150 to 150) static void PositionCB(BrickletRotaryPoti sender, short position) { Console.WriteLine("Position: " + position); }
private void RotaryEmit(BrickletRotaryPoti sender, short position) { _rotaryValue = position; }