Skip to content

Instantly share code, notes, and snippets.

@emsk
Created January 13, 2014 02:45
Show Gist options
  • Save emsk/8393953 to your computer and use it in GitHub Desktop.
Save emsk/8393953 to your computer and use it in GitHub Desktop.
ambient noren
/**
* ambient noren (Arduino)
*
* Receive z-axis acceleration from sensor and send it.
*
* - Mac OS X 10.8.5 Mountain Lion
* - SuperCollider 3.6.5 ... http://supercollider.sourceforge.net/
* - LilyPad Arduino USB ... https://www.sparkfun.com/products/11190
* - LilyPad Accelerometer ADXL335 ... https://www.sparkfun.com/products/9267
* - Flora Accelerometer LSM303 ... http://www.adafruit.com/products/1247
* - LilyPad XBee ... https://www.sparkfun.com/products/8937
* - LilyPad Slide Switch ... https://www.sparkfun.com/products/9350
*/
#include <Wire.h>
#include <LSM303.h>
#include <SoftwareSerial.h>
const int adxlPin = A2;
const int rxPin = 10;
const int txPin = 9;
int adxlZAxisAcceleration, lsmZAxisAcceleration, integratedAcceleration = 0;
LSM303 lsm;
SoftwareSerial xbee(rxPin, txPin);
void setup() {
pinMode(adxlPin, INPUT);
pinMode(txPin, OUTPUT);
Wire.begin();
lsm.init();
lsm.enableDefault();
xbee.begin(9600);
}
void loop() {
adxlZAxisAcceleration = analogRead(adxlPin);
lsm.read();
lsmZAxisAcceleration = (int)lsm.a.z;
integratedAcceleration = abs(adxlZAxisAcceleration) + abs(lsmZAxisAcceleration);
xbee.println(integratedAcceleration);
delay(100);
}
/**
* ambient noren (SuperCollider)
*
* Receive the sensor data and play the sound.
*
* - Mac OS X 10.8.5 Mountain Lion
* - SuperCollider 3.6.5 ... http://supercollider.sourceforge.net/
* - LilyPad Arduino USB ... https://www.sparkfun.com/products/11190
* - LilyPad Accelerometer ADXL335 ... https://www.sparkfun.com/products/9267
* - Flora Accelerometer LSM303 ... http://www.adafruit.com/products/1247
* - LilyPad XBee ... https://www.sparkfun.com/products/8937
* - LilyPad Slide Switch ... https://www.sparkfun.com/products/9350
*/
// 1. boot
(
s.options.device_("ASIO : ASIO4ALL v2");
s.boot;
)
// 2. define synth
(
SynthDef(\synthNoren, {
arg sensor = 1.0, pitch = #[52, 57, 62, 67, 71, 76];
var out = Mix.fill(pitch.size, {
arg i;
var trigger, pluck, period, string;
trigger = HPZ1.kr(sensor > (0.25 + (i * 0.1))).abs;
pluck = PinkNoise.ar(Decay.kr(trigger, 0.05));
period = pitch.at(i).midicps.reciprocal;
string = CombL.ar(pluck, period, period, 4);
Pan2.ar(string, i * 0.2 - 0.5);
});
LPF.ar(out, 12000);
LeakDC.ar(out);
Out.ar(0, out);
}).add;
)
(
~synthNoren = Synth(\synthNoren);
)
// 3. receive sensor data from Arduino
(
SerialPort.listDevices;
~arduino = ArduinoSMS("/dev/tty.usbserial-A702IZV6", 9600);
~arduino.action = {
arg ... msg;
var sensor = msg[0].asInteger.abs / 1000;
msg[0].postln;
~synthNoren.set(\sensor, sensor);
}
)
// 4. change pitch
~synthNoren.setn(\pitch, [52, 57, 62, 67, 71, 76]); // sample 1 (default)
~synthNoren.setn(\pitch, Array.series(15, 50, 7)); // sample 2
~synthNoren.setn(\pitch, Array.series(6, 52, 4)); // sample 3
// 5. quit
(
~arduino.close;
~synthNoren.free;
s.quit;
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment