Write to Arduino No firmata
Jump to navigation
Jump to search
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
1#define led01 12
2#define led02 13
3//constant from Touchdesigner
4byte degreesTouchdesigner; //setpoint send by Touchdesigner
5
6void setup() {
7 //start serial port at 9600 bps:
8 Serial.begin(9600);
9 while (!Serial)
10 {
11 ;// wait for serial port to connect. Needed for native USB port only.
12 }
13 // Declare pins as output:
14 pinMode(led01, OUTPUT);
15 pinMode(led02, OUTPUT);
16}
17
18void loop() {
19 if(Serial.available() > 0)
20 {
21 degreesTouchdesigner = Serial.read(); // read the values from Touchdesigner
22 Serial.print(degreesTouchdesigner);
23 if (degreesTouchdesigner>120)
24 {
25 digitalWrite(led01,LOW);
26 digitalWrite(led02,HIGH);
27 }
28 else
29 {
30 digitalWrite(led02,LOW);
31 digitalWrite(led01,HIGH);
32 }
33 }
34}
in TouchDesigner:
serial1 op
one per byte
CHOP Execute: select the CHOPS. Channels.
code:
1# me - this DAT
2#
3# channel - the Channel object which has changed
4# sampleIndex - the index of the changed sample
5# val - the numeric value of the changed sample
6# prev - the previous sample value
7#
8# Make sure the corresponding toggle is enabled in the CHOP Execute DAT.
9
10def onOffToOn(channel, sampleIndex, val, prev):
11 return
12
13def whileOn(channel, sampleIndex, val, prev):
14 return
15
16def onOnToOff(channel, sampleIndex, val, prev):
17 return
18
19def whileOff(channel, sampleIndex, val, prev):
20 return
21
22def onValueChange(channel, sampleIndex, val, prev):
23 op('serial1').sendBytes(val)
24 return