Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
                                          0x39,  0x5e, 0x79, 0x71 };// 0~9,A,b,C,d,E,F

        /// <summary>
        /// Anzeigen des Wertes am 7-Segment-Display
        /// </summary>
        /// <param name="value">Maximal 4 Stellen, nur Ganzzahlen</param>
        internal static void DisplayValue(string value)
        {
            try
            {
                int i3 = 0;
                int i2 = 0;
                int i1 = 0;
                int i0 = 0;

                int sl = value.Length;
                switch (sl)
                {
                case 1:
                    i0 = Convert.ToInt32(value[0]);
                    break;

                case 2:
                    i1 = Convert.ToInt32(value[0].ToString());
                    i0 = Convert.ToInt32(value[1].ToString());
                    break;

                case 3:
                    i2 = Convert.ToInt32(value[0].ToString());
                    i1 = Convert.ToInt32(value[1].ToString());
                    i0 = Convert.ToInt32(value[2].ToString());
                    break;

                case 4:
                    i3 = Convert.ToInt32(value[0].ToString());
                    i2 = Convert.ToInt32(value[1].ToString());
                    i1 = Convert.ToInt32(value[2].ToString());
                    i0 = Convert.ToInt32(value[3].ToString());
                    break;
                }
                //int i3 = Convert.ToInt32(value[3]), i2 = Convert.ToInt32(value[2]), i1 = Convert.ToInt32( value[1]), i0 = Convert.ToInt32(value[0]);
                IPConnection ipcon           = new IPConnection();                            // Create IP connection
                BrickletSegmentDisplay4x7 sd = new BrickletSegmentDisplay4x7(UID_SD7, ipcon); // Create device object

                ipcon.Connect(HOST, PORT);
                byte[] segments = { DIGITS[i3], DIGITS[i2], DIGITS[i1], DIGITS[i0] };
                sd.SetSegments(segments, 7, false);

                ipcon.Disconnect();
            }
            catch (Exception ex)
            {
                throw new Exception("Fehler beim Anzeigen des Wertes", ex);
            }
        }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Segment Display 4x7 Bricklet

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickletSegmentDisplay4x7 sd =
          new BrickletSegmentDisplay4x7(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Write "4223" to the display with full brightness without colon
        byte[] segments = {DIGITS[4], DIGITS[2], DIGITS[2], DIGITS[3]};
        sd.SetSegments(segments, 7, false);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Exemplo n.º 4
0
    public TetrisSegmentDisplay(IPConnection ipcon)
    {
        if (Config.UID_SEGMENT_DISPLAY_4X7_BRICKLET == null)
        {
            System.Console.WriteLine("Not Configured: Segment Display 4x7");
            return;
        }

        display = new BrickletSegmentDisplay4x7(Config.UID_SEGMENT_DISPLAY_4X7_BRICKLET, ipcon);

        try
        {
            string uid;
            string connectedUid;
            char   position;
            byte[] hardwareVersion;
            byte[] firmwareVersion;
            int    deviceIdentifier;

            display.GetIdentity(out uid, out connectedUid, out position,
                                out hardwareVersion, out firmwareVersion,
                                out deviceIdentifier);
            System.Console.WriteLine("Found: Segment Display 4x7 ({0})",
                                     Config.UID_SEGMENT_DISPLAY_4X7_BRICKLET);
        }
        catch (TinkerforgeException)
        {
            System.Console.WriteLine("Not Found: Segment Display 4x7 ({0})",
                                     Config.UID_SEGMENT_DISPLAY_4X7_BRICKLET);
            return;
        }

        okay = true;

        LineCountToDisplay();
    }