This example allows you to create a slider from an arbitrary number of pads which can be in any order.
The order of the pads and their pin numbering is defined in slider0Pads etc. We can also set the max number of centroid which will define how many touches can be registered per slider. This is currently set to 3 meaning that 3 individual touch points can be registered per sensor.
Each touch has a location and a touch size which equates to how hard the finger is pushing on the sensor. This example is particularly useful for working with Trill Flex and Trill Craft. When working with these sensors it always important to check that the Prescaler and Noisethreshold settings are optimum for your application. Experiment with different values if you are not getting a reading or seeing lots of cross talk between the sensors.
#include <cmath>
#include <libraries/Trill/Trill.h>
#include <libraries/Gui/Gui.h>
#include <libraries/Trill/CentroidDetection.h>
#define NUM_TOUCH 2
float gTouchLocation[NUM_TOUCH] = {0.0};
float gTouchSize[NUM_TOUCH] = {0.0};
int gNumActiveTouches = 0;
unsigned int gTaskSleepTime = 12000;
float gTimePeriod = 0.015;
void loop(void*)
{
{
touchSensor.readI2C();
cd.process(touchSensor.rawData.data());
for(unsigned int i = 0; i < cd.getNumTouches() ; i++) {
gTouchLocation[i] = cd.touchLocation(i);
gTouchSize[i] = cd.touchSize(i);
}
gNumActiveTouches = cd.getNumTouches();
usleep(gTaskSleepTime);
}
}
{
fprintf(stderr, "Unable to initialise Trill\n");
return false;
}
cd.
setup({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, NUM_TOUCH, 3200);
touchSensor.printDetails();
return true;
}
{
static unsigned int count = 0;
for(
unsigned int n = 0; n < context->
audioFrames; n++) {
{
gui.sendBuffer(0, gNumActiveTouches);
gui.sendBuffer(1, gTouchLocation);
gui.sendBuffer(2, gTouchSize);
count = 0;
}
count++;
}
}
{}
Definition CentroidDetection.h:7
A class to use the Trill family of capacitive sensors. http://bela.io/trill.
Definition Trill.h:14
@ CRAFT
Trill Craft
Definition Trill.h:36
@ DIFF
Definition Trill.h:25
AuxiliaryTask Bela_runAuxiliaryTask(void(*callback)(void *), int priority=0, void *arg=nullptr)
Create and start an AuxiliaryTask.
int Bela_stopRequested()
Check whether the program should stop.
void render(BelaContext *context, void *userData)
User-defined callback function to process audio and sensor data.
Definition render.cpp:68
bool setup(BelaContext *context, void *userData)
User-defined initialisation function which runs before audio rendering begins.
Definition render.cpp:51
void cleanup(BelaContext *context, void *userData)
User-defined cleanup function which runs when the program finishes.
Definition render.cpp:96
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition Bela.h:231
const uint32_t audioFrames
The number of audio frames per block.
Definition Bela.h:322
char projectName[MAX_PROJECTNAME_LENGTH]
Name of running project.
Definition Bela.h:417
const float audioSampleRate
The audio sample rate in Hz (currently always 44100.0).
Definition Bela.h:328