private static string UID = "XYZ"; // Change XYZ to the UID of your Multi Touch Bricklet

    #endregion Fields

    #region Methods

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

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

        // Get current touch state
        int state = mt.GetTouchState();
        string str = "";

        if((state & (1 << 12)) == (1 << 12)) {
            str += "In proximity, ";
        }

        if((state & 0xfff) == 0) {
            str += "No electrodes touched";
        } else {
            str += "Electrodes ";
            for(int i = 0; i < 12; i++) {
                if((state & (1 << i)) == (1 << i)) {
                    str += i + " ";
                }
            }
            str += "touched";
        }

        Console.WriteLine(str);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    private static string UID  = "XYZ";    // Change to your UID

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

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

        // Get current touch state
        int touchState = mt.GetTouchState();

        string str = "";

        if ((touchState & (1 << 12)) == (1 << 12))
        {
            str += "In proximity, ";
        }

        if ((touchState & 0xfff) == 0)
        {
            str += "No electrodes touched" + System.Environment.NewLine;
        }
        else
        {
            str += "Electrodes ";
            for (int i = 0; i < 12; i++)
            {
                if ((touchState & (1 << i)) == (1 << i))
                {
                    str += i + " ";
                }
            }
            str += "touched" + System.Environment.NewLine;
        }

        System.Console.WriteLine(str);

        System.Console.WriteLine("Press enter to exit");
        System.Console.ReadLine();
        ipcon.Disconnect();
    }
Example #3
0
        //multi touch
        public void TouchStateCB(BrickletMultiTouch sender, int state)
        {
            Console.WriteLine(_multiTouch.GetTouchState());
            int    key = 0;
            string str = "";

            if ((state & (1 << 12)) == (1 << 12))
            {
                str += "In proximity, ";
            }

            if ((state & 0xfff) == 0)
            {
                str += "No electrodes touched";
            }
            else
            {
                str += "Electrodes ";
                for (int i = 0; i < 12; i++)
                {
                    if ((state & (1 << i)) == (1 << i))
                    {
                        str += i + " ";
                        key  = i;
                    }
                }

                switch (key)
                {
                case 0:
                    while (_multiTouch.GetTouchState() == 4097)
                    {
                        SendKeys.SendWait("{DOWN}");
                    }

                    break;

                case 1:
                    while (_multiTouch.GetTouchState() == 4098)
                    {
                        SendKeys.SendWait("{LEFT}");
                    }

                    break;

                case 2:
                    while (_multiTouch.GetTouchState() == 4100)
                    {
                        SendKeys.SendWait("{RIGHT}");
                    }

                    break;

                case 3:
                    while (_multiTouch.GetTouchState() == 4104)
                    {
                        SendKeys.SendWait("{UP}");
                    }

                    break;

                case 6:
                    while (_multiTouch.GetTouchState() == 4160)
                    {
                        SendKeys.SendWait("{X}");
                    }

                    break;

                case 7:
                    while (_multiTouch.GetTouchState() == 4224)
                    {
                        SendKeys.SendWait("{Z}");
                    }

                    break;

                default:
                    break;
                }


                str += "touched";
            }

            Console.WriteLine(str);
        }