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 Craft sensor to best suit your needs.
There are two important sensor settings that you may want to adjust when working with the Trill Craft: the threshold and the prescaler.
 
#include <libraries/Trill/Trill.h>
#include <libraries/Gui/Gui.h>
#include <libraries/Pipe/Pipe.h>
 
 
 
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();
 
                
                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 Craft\n");
                return false;
        }
 
        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);
                        count = 0;
                }
                count++;
        }
}
 
{
}
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
Mode
Definition Trill.h:19
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