‹ Pd on Raspberry Pi audioSerial ›

SuperCollider Firmata

2014-10-21 13:28 supercollider

clean-up: #57

Just cleaned up an example for SuperCollider and Arduino that I found on my computer. It is demonstrating the SCFirmata class by Eirik Arthur Blekesaune.

//how to read pin A0 with SCFirmata...

//for Arduino1.0.6 and SC3.6.6
//first in Arduino IDE:
//  * select File / Examples / Firmata / StandardFirmata
//  * upload this example to an Arduino
//then in SC install the SCFirmata classes
//  * download zip file https://github.com/blacksound/SCFirmata
//  * extract files and put them in your SC application support directory
//  * recompile SC

SerialPort.devices
d= SerialPort.devices[0]; // or d= "/dev/tty.usbserial-A1001NeZ" - edit number (or string) to match your Arduino
f= FirmataDevice(d);//if it works it should post 'Protocol version: 2.3' after a few seconds

s.boot
Ndef(\snd, {|freq= 400, amp= 0.5| SinOsc.ar([freq, freq+4].lag(0.08), 0, amp.lag(0.08)).tanh}).play;
f.reportAnalogPin(0, true)  //start reading A0
f.analogPinAction= ({|num, val| [num, val].postln; Ndef(\snd).set(\freq, val.linexp(0, 1023, 400, 800))})//control freq
f.analogPinAction= ({|num, val| [num, val].postln; Ndef(\snd).set(\amp, val.linexp(0, 1023, 0.001, 1))})//control amp instead

Ndef(\snd).stop
f.reportAnalogPin(0, false)  //stop reading A0
f.end
f.close

‹ Pd on Raspberry Pi audioSerial ›