Difference between revisions of "Write to Arduino No firmata"
Jump to navigation
Jump to search
Line 16: | Line 16: | ||
===Arduino code === | ===Arduino code === | ||
− | <syntaxhighlight lang="C" | + | <syntaxhighlight lang="C" > |
#define led01 12 | #define led01 12 | ||
#define led02 13 | #define led02 13 |
Latest revision as of 15:24, 4 April 2024
1. Send data from Touchdesigner
Firmata
Palette —> tools —> Firmata
CHOP Execute DAT =
2. Arduino received data
Firmata
file --> example --> Firmata --> StanderFirmata
Serial.read()
Arduino code
#define led01 12
#define led02 13
//constant from Touchdesigner
byte degreesTouchdesigner; //setpoint send by Touchdesigner
void setup() {
//start serial port at 9600 bps:
Serial.begin(9600);
while (!Serial)
{
;// wait for serial port to connect. Needed for native USB port only.
}
// Declare pins as output:
pinMode(led01, OUTPUT);
pinMode(led02, OUTPUT);
}
void loop() {
if(Serial.available() > 0)
{
degreesTouchdesigner = Serial.read(); // read the values from Touchdesigner
Serial.print(degreesTouchdesigner);
if (degreesTouchdesigner>120)
{
digitalWrite(led01,LOW);
digitalWrite(led02,HIGH);
}
else
{
digitalWrite(led02,LOW);
digitalWrite(led01,HIGH);
}
}
}
in TouchDesigner:
serial1 op
one per byte
CHOP Execute: select the CHOPS. Channels.
code:
# me - this DAT
#
# channel - the Channel object which has changed
# sampleIndex - the index of the changed sample
# val - the numeric value of the changed sample
# prev - the previous sample value
#
# Make sure the corresponding toggle is enabled in the CHOP Execute DAT.
def onOffToOn(channel, sampleIndex, val, prev):
return
def whileOn(channel, sampleIndex, val, prev):
return
def onOnToOff(channel, sampleIndex, val, prev):
return
def whileOff(channel, sampleIndex, val, prev):
return
def onValueChange(channel, sampleIndex, val, prev):
op('serial1').sendBytes(val)
return