// Example using shaking of laptop (squared velocity as detected // by internal accelerometers) to shake model of coin in mug // by Perry R. Cook, based on examples from 1996+ // this version for ICAD Sonification Workshop, June 2012 Shakers peso => JCRev rev => dac.right; // coin in coffee mug 19 => peso.preset; 10 => peso.objects; 1.0 => peso.decay; // setup 0.03 => rev.mix; 1 => peso.noteOn; // git this party started Hid hi; // make a Hid object HidMsg msg; // and holder for messages if( !hi.openTiltSensor() ) { // open tilt sensor <<< "tilt sensor unavailable", "" >>>; me.exit(); } <<< "tilt sensor ready", "" >>>; // if success opening hid float lacc[3]; // to hold our last accel values while( true ) { hi.read( 9, 0, msg ); // read accel (device 9) number 0 // <<< msg.x, msg.y, msg.z >>>; // print results (msg.x - lacc[0])*(msg.x - lacc[0]) => float shaking; // get total (msg.y - lacc[1])*(msg.y - lacc[1]) +=> shaking; // 3D squared (msg.z - lacc[2])*(msg.z - lacc[2]) +=> shaking; // velocity shaking / 4000.0 => peso.energy; // and use that to shake model msg.x => lacc[0]; msg.y => lacc[1]; msg.z => lacc[2]; // store last values 30 :: ms => now; // hang out until next read }