예제 #1
0
파일: Component.cs 프로젝트: dntichy/IOT
        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;
        }
예제 #2
0
        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();
        }
예제 #3
0
파일: Component.cs 프로젝트: dntichy/IOT
        public void PositionCb(BrickletLinearPoti sender, int position)
        {
            Console.WriteLine("Position: " + position);
            _red = (byte)(RED + ((position - 75) * 2));
            _rgbButton.SetColor(_red, _green, _blue);
            WriteDigits(_red + _green + _blue);


            byte vIn  = 0;
            int  vOut = Convert.ToInt32(vIn);

            Console.WriteLine();
        }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Linear Poti Bricklet

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletLinearPoti lp = new BrickletLinearPoti(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 0 to 100)
        int position = lp.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 Linear Poti Bricklet

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletLinearPoti lp = new BrickletLinearPoti(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
        lp.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!
        lp.SetPositionCallbackPeriod(50);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
 // Callback function for position callback (parameter has range 0 to 100)
 static void PositionCB(BrickletLinearPoti sender, int position)
 {
     Console.WriteLine("Position: " + position);
 }