First Arduino project so might need some help! I have successfully got data from one distance sensor into Touch Designer, however the next step I want to do it use two. I have them both set up and working in Arduino sketch, but don’t know how to separate the data to go into Touch Designer. So one sensor can control one parameter and the other can control another - can’t seem to separate them. through the serial and select operators. Any advice or suggestions would be appreciated!
Here is my Arduino code (most likely far from perfect):
// ULTRASONIC SENSOR
int TRIG = 3;
int ECHO = 2;
int DURATION;
int DISTANCE;
int TRIG_2 = 8;
int ECHO_2 = 7;
int DURATION_2;
int DISTANCE_2;
void setup() {
// ULTRASONIC SENSOR
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(TRIG_2, OUTPUT);
pinMode(ECHO_2, INPUT);
// SERIAL
Serial.begin(9600);
}
void loop() {
//LEFT SENSOR
digitalWrite(TRIG,HIGH);
delay(1);
digitalWrite(TRIG,LOW);
DURATION = pulseIn(ECHO,HIGH);
DISTANCE = DURATION / 58.2;
if(DISTANCE > 0 && DISTANCE < 50 )
Serial.println(DISTANCE);
delay(100);
//RIGHT SENSOR
digitalWrite(TRIG_2,HIGH);
delay(1);
digitalWrite(TRIG_2,LOW);
DURATION_2 = pulseIn(ECHO_2,HIGH);
DISTANCE_2 = DURATION_2 / 58.2;
if(DISTANCE_2 > 0 && DISTANCE_2 < 50 ){
Serial.println(DISTANCE_2);
delay(100);
}
}