Hello everyone.
I'm working on a modular synthesizer controller project with Bela Trill sensors and I'm having some trouble using multiple sensors.
My goal is to use multiple trill sensors, hook it up to Arduino Uno to control separate PWM output values. For example, Trill Bar sensor to control anlalog output 9's PWM value and Trill Circle sensor to control analog output 10's PWM value. I'm using Trill Hub to connect multiple sensors into Arduino Uno.
So far, I got one output working but I'm having trouble running multiple sensors simultaneously and outputting separate values.
Below is the code I put together. I'm relatively new so I'm not even sure if it's achievable with Arduino Uno.
Thank you in advance for the help.
#include <Trill.h>
Trill trillSensor;
boolean touchActive = false;
void setup() {
// Initialise serial and touch sensor
Serial.begin(115200);
int ret = trillSensor.setup(Trill::TRILL_BAR);
if(ret != 0) {
Serial.println("failed to initialise trillSensor");
Serial.print("Error code: ");
Serial.println(ret);
pinMode(9, OUTPUT);
}
//int ret1 = trillSensor.setup(Trill::TRILL_RING);
//if(ret1 != 0) {
//Serial.println("failed to initialise trillSensor");
//Serial.print("Error code: ");
//Serial.println(ret1);
// pinMode(10, OUTPUT);
//}
}
void loop() {
{
// Read 20 times per second
delay(50);
trillSensor.read();
int touchValue = trillSensor.touchLocation(0)/255;
int brightness = map(touchValue, 0, 255, 0, 255);
analogWrite(9, brightness);
}
{
//delay(50);
//trillSensor.read();
//int touchValue2 = trillSensor.touchLocation(0)/255;
//int brightness2 = map(touchValue, 0, 255, 0, 255);
//analogWrite(10, brightness);
}
if(trillSensor.getNumTouches() > 0) {
for(int i = 0; i < trillSensor.getNumTouches(); i++) {
Serial.print(trillSensor.touchLocation(i));
Serial.print(" ");
Serial.print(trillSensor.touchSize(i));
Serial.print(" ");
}
//if(trillSensor.getNumTouches() > 0) {
//for(int i = 0; i < trillSensor.getNumTouches2(); i++) {
//Serial.print(trillSensor.touchLocation2(i));
//Serial.print(" ");
//Serial.print(trillSensor.touchSize2(i));
//Serial.print(" ");
}
{
Serial.println("");
touchActive = true;
}
// else if(touchActive) {
// Print a single line when touch goes off
Serial.println("0 0");
touchActive = false;
}