Here is a suggestion for an alternative method to read touch inputs on the Teensy 3.2. The Teensyduino library function touchRead() waits for the result before returning, so it may be too slow or cause excess delay to other tasks in some applications. Such was the case with an application I am developing. (It's a MIDI EWI synth. The maximum tolerable latency to read all 12 touch pads is about 10ms.)
My suggested method defines 3 new functions: touchSenseInit(pin), touchSenseDone() and touchSenseRead(). A test sketch is attached to show how (up to) 12 touch input readings can be acquired (continuously updated) without "blocking", i.e. without causing delay to other "background" tasks executing in the main loop. Note: The test sketch does not include any code to output the touch readings. This is left to the reader to implement. You could use the (USB) Serial library functions to output readings to the host PC running a terminal emulator (e.g. PuTTY -- or the Arduino "Serial Monitor").
I vaguely remember reading somewhere that the touchRead() function's maximum reading is 60,000, but I can't find anywhere in the code where this limit is imposed. Using my scheme, a time-out can be easily imposed. This would further reduce any latency due to touch sensing. There is another post somewhere on this forum which explains how the 10us delay can also be removed from the touchRead() function.
View attachment teensy32_touch_sense.ino
Oops... the program I attached to my post contains an error. Here is the corrected version.
The forum page says I can edit posts, but I can't see how. If anyone can enlighten me, I would be grateful.
View attachment 24050
My suggested method defines 3 new functions: touchSenseInit(pin), touchSenseDone() and touchSenseRead(). A test sketch is attached to show how (up to) 12 touch input readings can be acquired (continuously updated) without "blocking", i.e. without causing delay to other "background" tasks executing in the main loop. Note: The test sketch does not include any code to output the touch readings. This is left to the reader to implement. You could use the (USB) Serial library functions to output readings to the host PC running a terminal emulator (e.g. PuTTY -- or the Arduino "Serial Monitor").
I vaguely remember reading somewhere that the touchRead() function's maximum reading is 60,000, but I can't find anywhere in the code where this limit is imposed. Using my scheme, a time-out can be easily imposed. This would further reduce any latency due to touch sensing. There is another post somewhere on this forum which explains how the 10us delay can also be removed from the touchRead() function.
View attachment teensy32_touch_sense.ino
Oops... the program I attached to my post contains an error. Here is the corrected version.
The forum page says I can edit posts, but I can't see how. If anyone can enlighten me, I would be grateful.
View attachment 24050
Last edited by a moderator: