Once the project is running click the GUI button to see the reading on each channel. From this GUI you can also adjust the setting of the sensor to best suit your needs.
There are two important sensor settings that you may want to adjust when working with Trill Flex: the threshold and the prescaler.
 
#include <libraries/Trill/Trill.h>
#include <libraries/Gui/Gui.h>
#include <libraries/Pipe/Pipe.h>
#include <libraries/Trill/CentroidDetection.h>
 
#define NUM_TOUCH 4 
 
 
 
float gTouchLocation[NUM_TOUCH] = {0.0};
float gTouchSize[NUM_TOUCH] = {0.0};
int gNumActiveTouches = 0;
 
 
unsigned int gTaskSleepTime = 12000; 
 
float gTimePeriod = 0.015;
 
int bitResolution = 12;
 
int gButtonValue = 0;
 
typedef enum {
        kPrescaler,
        kBaseline,
        kNoiseThreshold,
        kNumBits,
        kMode,
} ids_t;
        ids_t id;
        float value;
};
 
#include <tuple>
std::vector<std::pair<std::wstring, ids_t>> gKeys =
{
        {L"prescaler", kPrescaler},
        {L"baseline", kBaseline},
        {L"noiseThreshold", kNoiseThreshold},
        {L"numBits", kNumBits},
        {L"mode", kMode},
};
 
bool guiCallback(JSONObject& json, void*)
{
        for(auto& k : gKeys)
        {
                if(json.find(k.first) != json.end() && json[k.first]->IsNumber())
                {
                        command.id = k.second;
                        command.value = json[k.first]->AsNumber();
                        gPipe.writeNonRt(command);
                }
        }
        return false;
}
 
void loop(void*)
{
        int numBits;
        int speed = 0;
        {
                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();
                
 
                
                while(1 == gPipe.readRt(command))
                {
                        float value = command.
value;
 
                        {
                                case kPrescaler:
                                        printf("setting prescaler to %.0f\n", value);
                                        touchSensor.setPrescaler(value);
                                        break;
                                case kBaseline:
                                        printf("reset baseline\n");
                                        touchSensor.updateBaseline();
                                        break;
                                case kNoiseThreshold:
                                        printf("setting noiseThreshold to %f\n", value);
                                        touchSensor.setNoiseThreshold(value);
                                        break;
                                case kNumBits:
                                        numBits = value;
                                        printf("setting number of bits to %d\n", numBits);
                                        touchSensor.setScanSettings(speed, numBits);
                                        break;
                                case kMode:
                                        printf("setting mode to %.0f\n", value);
                                        break;
                        }
                }
                usleep(50000);
        }
}
 
{
        
                fprintf(stderr, "Unable to initialise Trill Flex\n");
                return false;
        }
        
        
        
        
        cd.setup(30, NUM_TOUCH, 3200);
 
        gui.setControlDataCallback(guiCallback, nullptr);
        gPipe.setup("guiToLoop");
 
        return true;
}
 
{
        static unsigned int count = 0;
 
        for(
unsigned int n = 0; n < context->
audioFrames; n++) {
 
                
                
                {
                        gui.sendBuffer(0, touchSensor.getNumChannels());
                        gui.sendBuffer(1, touchSensor.rawData);
                        gui.sendBuffer(2, gNumActiveTouches);
                        gui.sendBuffer(3, gTouchLocation);
                        gui.sendBuffer(4, 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
@ FLEX
Trill Flex
Definition Trill.h:39
Mode
Definition Trill.h:19
@ 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