Skip to content

Instantly share code, notes, and snippets.

@chriskiefer
Created February 10, 2016 15:20
Show Gist options
  • Save chriskiefer/4c7788047343b5119e93 to your computer and use it in GitHub Desktop.
Save chriskiefer/4c7788047343b5119e93 to your computer and use it in GitHub Desktop.
Example code from an AHRC CCN+ workshop, exploring minimalist musical notation cues with LEDs and vibrators. The code shows how the LEDs were controlled.
SerialPort.listDevices
q = SerialPort.new('/dev/tty.usbmodem1411', 115200);
~jo = NetAddr(~ipAddress, 57120);
~jo.sendMsg(\clock)
~jo.sendBundle(0, [\clock])
(
~led = {|i, r, g, b| q.putAll([i, round(r*255), round(g*255), round(b*255)].as(Int8Array))};
~bpm = 80;
~ppqn = 12;
~pos = 0;
Tdef(\clock, {
inf.do({
var waitTime = (60/~bpm/~ppqn);
~jo.sendMsg(\clock, ~pos);
(waitTime * 0.5).wait;
~onTick.(~pos);
~pos = ~pos + 1;
(waitTime * 0.5).wait;
});
}).play;
)
Tdef(\clock).stop
(
~cols = {{1.0.rand}!3}!4;
~onTick = {|p|
~leds = 0!3!16;
// ~bpm = (sin(p/90).linlin(-1,1,60,120));
// ~bpm.postln;
// (3,7..15).do({|v|
// ~led.(v,0,0,~bpm.linlin(60,120,0,1));
// });
//p.postln;
// 16.do({|i|
// // ~led.(i, sin(p/200) + 1 / 2, 0.0 + ((p/10)%16) / 16, (i==(p%16)).if(0, 0.4));
// // ~led.(i, 0, 0, (i==(p%16)).if(0, 0.4));
// // ~led.(i, 0, ((p%16)==i).if(0,1), 0);
// ~led.(i, 0, 0, 0);
// });
// [[2,6,10,14],[4,4,2,2]].flop.do({|v|
// (p%(~ppqn * v[1])<2).if({
// // ~led.(v[0], 0, 1, 0);
// ~leds[v[0]] = [0,1,0];
// }, {
// // ~led.(v[0], 0, 0, 0);
// ~leds[v[0]] = [0,0,0];
// });
// });
// (p%(~ppqn * 4)<2).if({
// ~led.(2, 0, 1, 0);
// }, {
// ~led.(2, 0, 0, 0);
// }
// );
//
// (p%(~ppqn * 4)<2).if({
// ~led.(6, 0, 1, 0);
// }, {
// ~led.(6, 0, 0, 0);
// }
// );
//
// (p%(~ppqn * 2)<2).if({
// ~led.(10, 0, 1, 0);
// }, {
// ~led.(10, 0, 0, 0);
// }
// );
//
//
// (p%(~ppqn * 2)<2).if({
// ~led.(14, 0, 1, 0);
// }, {
// ~led.(14, 0, 0, 0);
// }
// );
// (p%(~ppqn * 4)==0).if({
// ~cols = {{1.0.rand}!3}!4;
// });
// (1,5..15).do({|v,i|
// ~leds[v] = [ ~cols[i][0], ~cols[i][1], ~cols[i][2]];
// });
// (p%12<2).if({
// (0,4..15).do({|i|
// ~leds[i] = [0,1,0];
//
// });
// }, {
// (0,4..15).do({|i|
// ~leds[i] = [0,0,0];
// });
// // (1,5..15).do({|v,i|
// // ~leds[i] = [0,0,0];
// // });
// });
// ~leds.do({|v,i|~led.(i, v[0], v[1], v[2]);});
// ~leds.do({|v,i|~led.(i, sin(p/100).linlin(-1,1,0,1), sin(p/30).linlin(-1,1,0,1), sin(p/30).linlin(-1,1,0,1));});
~sp = 1;
~mf = {|x|(sin(x)**2).madd(1,0).wrap(-1,1)};
[0,1].do({|i|~leds[i] = [~mf.(p/50 * ~sp).linlin(-1,1,0,1),
~mf.(p/10 * ~sp).linlin(-1,1,0,1),
~mf.(p/40 * ~sp).linlin(-1,1,0,1)] ;});
(2..3).do({|i|~leds[i] = [~mf.(p/50 * ~sp).linlin(-1,1,0,1),
~mf.(p/100 * ~sp).linlin(-1,1,0,1),
~mf.(p/40 * ~sp).linlin(-1,1,0,1)];});
(4..7).do({|i|~leds[i] = [~mf.(p/20 * ~sp).linlin(-1,1,0,1),
~mf.(p/40 * ~sp).linlin(-1,1,0,1),
~mf.(p/90 * ~sp).linlin(-1,1,0,1)];});
// (6..7).do({|i|~leds[i] = [sin(p/20 * ~sp).linlin(-1,1,0,1),
// sin(p/100 * ~sp).linlin(-1,1,0,1),
// sin(p/120 * ~sp).linlin(-1,1,0,1)];});
(8..11).do({|i|~leds[i] = [~mf.(p/40 * ~sp).linlin(-1,1,0,1),
~mf.(p/50 * ~sp).linlin(-1,1,0,1),
~mf.(p/70 * ~sp).linlin(-1,1,0,1)];});
[12,13,14,15].do({|i|~leds[i] = [~mf.(p/20 * ~sp).linlin(-1,1,0,1),
~mf.(p/50 * ~sp).linlin(-1,1,0,1),
~mf.(p/80 * ~sp).linlin(-1,1,0,1)];});
[13,14].do({|i|~leds[i] = [sin(p/20 * ~sp).linlin(-1,1,0,1),
sin(p/10 * ~sp).linlin(-1,1,0,1),
sin(p/80 * ~sp).linlin(-1,1,0,1)];});
[0,4,8,12].do({|i|~leds[i] = [sin(p/140 * ~sp).linlin(-1,1,0,1),
sin(p/100 * ~sp).linlin(-1,1,0,1),
sin(p/190 * ~sp).linlin(-1,1,0,1)];});
(0..3).do({|i| ~leds[i] = ~leds[i] * sin(p/50).abs.pow(1.9)});
(4..7).do({|i| ~leds[i] = ~leds[i] * sin(p/150).abs.pow(3)});
(8..11).do({|i| ~leds[i] = ~leds[i] * sin(p/180).abs.pow(1.4)});
(12..15).do({|i| ~leds[i] = ~leds[i] * sin(p/90).abs.pow(1)});
// ~leds = ~leds * sin(p/100).abs.pow(1.4);
~leds = ~leds * 0.99;
// ~leds[(p*0.1)%16] = ~leds[(p*0.1)%16] * 0.1;
~leds.do({|v,i|~led.(i, v[0], v[1], v[2]);});
};
)
~led.(12, 1, 0.0, 1)
q.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment