This is an example of how to communicate with the Trill Bar sensor using the Trill library. We also visualise position of each touch in real time via the integrated Bela p5.js GUI.
The Trill sensor is scanned in an AuxiliaryTask running in parallel with the audio thread and the number of active touches, their position and size are stored in global variables.
Click the GUI button to see a visualisation of the sensor. Up to 5 touches position with touch size are displayed in the sketch.
#include <cmath>
#include <libraries/Trill/Trill.h>
#include <libraries/Gui/Gui.h>
#define NUM_TOUCH 5 // Number of touches on Trill sensor
float gTouchLocation[NUM_TOUCH] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
float gTouchSize[NUM_TOUCH] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
int gNumActiveTouches = 0;
unsigned int gTaskSleepTime = 12000;
float gTimePeriod = 0.015;
void loop(void*)
{
{
for(unsigned int i = 0; i < gNumActiveTouches; i++) {
}
for(unsigned int i = gNumActiveTouches; i < NUM_TOUCH; i++) {
gTouchLocation[i] = 0.0;
gTouchSize[i] = 0.0;
}
usleep(gTaskSleepTime);
}
}
{
fprintf(stderr, "Unable to initialise Trill Bar\n");
return false;
}
usleep(10000);
return true;
}
{
static unsigned int count = 0;
for(
unsigned int n = 0; n < context->
audioFrames; n++) {
{
count = 0;
}
count++;
}
}
{}