Skip to content

Instantly share code, notes, and snippets.

@jarmitage
Created July 11, 2019 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarmitage/8c2628bea419351a4850a493e98a69af to your computer and use it in GitHub Desktop.
Save jarmitage/8c2628bea419351a4850a493e98a69af to your computer and use it in GitHub Desktop.
Bela SuperCollider Printing Sensors
( // connect to the already-running remote belaserver
Server.default = s = Server("belaServer", NetAddr("192.168.7.2", 57110));
s.options.maxLogins = 4; // should match the settings on the Bela
s.initTree;
s.startAliveThread;
);
(
// msgArray = [button, fsr, knob] // every three SendTrig's
~msgArray = [0,0,0];
~count = 3;
~counter = 0;
o = OSCresponderNode(s.addr, '/tr', { arg time,resp,msg;
// msg[ /tr, nodeID, id, value]
if (msg[2] == 0, // button
{~msgArray.put(0, msg[3].asStringPrec(0))},
{}
);
if (msg[2] == 1, // fsr
{
msg[3] = msg[3] / 0.78;
~msgArray.put(1, msg[3].asStringPrec(2))
},
{}
);
if (msg[2] == 2, // knob
{
msg[3] = msg[3] / 0.83;
~msgArray.put(2, msg[3].asStringPrec(2))},
{}
);
~counter = ~counter + 1;
if (~counter == ~count,
{
"[Bela] Button: ".post;
~msgArray[0].post;
" FSR: ".post;
~msgArray[1].post;
" Knob: ".post;
~msgArray[2].postln;
~counter = 0;
},
{}
);
}).add;
// o.remove;
);
("/path/to/bela_startup.scd").load;
(
SynthDef("synth",{ arg out=0;
var button = DigitalIn.kr(0);
var fsr = AnalogIn.ar(0);
var knob = AnalogIn.ar(1);
// Do not delete SendTrig: this enables printing to the console
SendTrig.kr(Impulse.kr(10), [0,1,2], [button,fsr,knob]);
Out.ar(out,
SinOsc.ar( 400, [0,0], 0.1)
)
}).send(s);
);
a = Synth.new("synth", target: s).postln;
a.free;
@jarmitage
Copy link
Author

Messy code. Note this uses the deprecated OSCresponderNode, should be replaced with OSCdef / OSCFunc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment