Saturday, February 8, 2025

5.1 working in touchdesigner

This week we worked with outputs created by an arduino that create effects in touchdesigner and outputs from touchdesigner generators that cause effects on the arduino.


This program reads a voltage from a potentiometer and sends it as a value from 1-255 using the Serial.write function (which sends the number as one byte of data as opposed to serial.print, which sends each numeral as an individual byte).


By selecting the USB port the arduino is connected to in the 'port' subsetting of a Serial DAT, the values created by the arduino can be used as inputs within a touch designer program. The network below has the serial number coming in, being sent to a 'data' node through the python code connected to the 'serial' node, being converted to a degree value in the 'math' node, and then sent to a null to have an effect on the movie file. 

this code sends the serial number to the data operator:

    def onReceive(dat, rowIndex, message, byteData):

op('text1').text = int.from_bytes(byteData, "big")
return




Conversely, we can also generate data inside touchdesigner that has an effect on a physical arduino device. For example, this slider can be combined with a math (for conversion) and a null node to send data to a PWM pin to control the brightness of an LED.

For this example, the pre-set LED brightness example in the Arduino IDE will work.

Instead of receiving serial data from the arduino, this python script allows serial data to be sent to the arduino, which controls the brightness:


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


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

14.1 project 2 prototypes/planning

I began prototyping this week by mapping out all the individual elements I need to construct for my seed growing lamp, which has become some...