TOUCHPixx Demo 1 -- Creating a touchscreen whac-a-mole with the TOUCHPixx =============================================================================== In this demo, we simulate a whack-a-mole game to demonstrate how to use the TOUCHPixx data. To use the TOUCHPixx, a calibration must be done to convert from TOUCHPixx coordinates to screen coordinates. Since we are working on a simple 2-dimension space, two points (two corners) is enough to offer a linear mapping to the entire touch screen. To start using the TOUCHPixx, we must set the digital inputs properly. This is done with ``Datapixx('EnableTouchpixx');``. As the RESPONSEPixx, we must stabilize inputs on the TOUCHPixx ``Datapixx('SetTouchpixxStabilizeDuration', 0.01)``, where 0.01 means a press must last 10 ms before it is considered an input. When there is no press, ``Datapixx('GetTouchpixxCoordinates');`` returns zero for both x and y. This function returns an array which includes the x coordinate in the first position and y coordinate in the second. These are raw coordinates and must be calibrated. A linear mapping must be created with the two known coordinates by simply creating an equation :math:`Real_x = m_x*TOUCHPixx_x + b_x`. Since we took two points, we can find the unknown :math:`m_x,~ b_x`. To log all touches, we start a logger ``Datapixx('SetTouchpixxLog');`` and we set the mode to be continuous ``Datapixx('EnableTouchpixxLogContinuousMode');`` so that we can sweep and still have a recorded input. To get the coordinates, we first ask for a status to know if any input occurred: ``status = Datapixx('GetTouchpixxStatus');`` and check the ``newLogFrames`` arguments of ``status``. Once we know there are new frames, we can read the presses and timetags: ``[touches timetags] = Datapixx('ReadTouchpixxLog', status.newLogFrames);``. Remember that these are raw coordinates and must be converted. .. literalinclude:: ../DatapixxToolbox/DatapixxDemos/TouchpixxWhacAMoleDemo.m :language: matlab :emphasize-lines: 30-31, 86-89, 133-136, 149-151 :linenos: