Materials for the SC@NIME2020 workshop
Notional rather than working examples it’s often more convenient to use higher level approaches (e.g. Modality) to these
https://en.wikipedia.org/wiki/Human_interface_device
HID.postAvailable; // check which devices are attached
~myhid = HID.open( 1103, 53251 ); // open the Run 'N' Drive game controller, put your own values here.
s.boot; // boot the server
Ndef(\sinewave, { |freq=500, amp=0.1| SinOsc.ar( freq, 0, amp * 0.2 ) } );
Ndef(\sinewave ).play;
HIDdef.usage( \freq, { |value| Ndef( \sinewave ).set(\freq, value.linexp( 0, 1, 500, 5000 ) ); }, \X );
HIDdef.usage( \amp, { |value| Ndef( \sinewave ).set(\amp, value ); }, \Y );
(
p = SerialPort(
"/dev/tty.usbserial-A800crTT", // edit to match your port. SerialPort.listDevices
baudrate: 9600, // check that baudrate is the same as in arduino sketch
crtscts: true); // use hardware flow control
)
// read 10bit serial data sent from Arduino's Serial.println
(
r= Routine({
var byte, str, res;
99999.do{|i|
if(p.read==10, {
str = "";
while({byte = p.read; byte !=13 }, {
str= str++byte.asAscii;
});
res= str.asInteger;
("read value:"+res).postln;
});
};
}).play;
)