#include <libraries/Trill/Trill.h>
#include <cmath>
#define NUM_TOUCH 5
#define NUM_LED 12
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.01;
unsigned int gLedPins[NUM_LED] = { 0, 1, 2, 3, 4, 5, 8, 9, 11, 12, 13, 14 };
bool gLedStatus[NUM_LED] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
void loop(void*)
{
{
touchSensor.readI2C();
gNumActiveTouches = touchSensor.getNumTouches();
for(unsigned int i = 0; i < gNumActiveTouches; i++)
{
gTouchLocation[i] = touchSensor.touchLocation(i);
gTouchSize[i] = touchSensor.touchSize(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;
}
for(unsigned int l = 0; l < NUM_LED; l++)
pinMode(context, 0, gLedPins[l], OUTPUT);
return true;
}
{
bool activeSections[NUM_LED] = { false };
static unsigned int count = 0;
for(
unsigned int n = 0; n < context->
audioFrames; n++) {
for(unsigned int t = 0; t < gNumActiveTouches; t++) {
int section = floor( NUM_LED * gTouchLocation[t] );
activeSections[section] = activeSections[section] || 1;
}
for(unsigned int l = 0; l < NUM_LED; l++) {
gLedStatus[l] = activeSections[l];
}
{
for(unsigned int l = 0; l < NUM_LED; l++)
rt_printf("%d ",gLedStatus[l]);
rt_printf("\n");
count = 0;
}
count++;
}
}
{}
A class to use the Trill family of capacitive sensors. http://bela.io/trill.
Definition Trill.h:14
void printDetails()
Definition Trill.cpp:492
@ BAR
Trill Bar
Definition Trill.h:34
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.
static void digitalWrite(BelaContext *context, int frame, int channel, int value)
Write a digital output, specifying the frame number (when to write) and the pin.
Definition Bela.h:1525
static void pinMode(BelaContext *context, int frame, int channel, int mode)
Set the direction of a digital pin to input or output.
Definition Bela.h:1548
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
const float audioSampleRate
The audio sample rate in Hz (currently always 44100.0).
Definition Bela.h:328