Page 218 - Hacking Roomba
P. 218
Chapter 10 — Using Roomba as an Input Device 199
FIGURE 10-8: Alternate playing method, used in RoombaThereminToo
Listing 10-3: RoombaThereminToo, Using Ess and Hand-Waving
Channel mySoundA;
void setup() {
// ... other standard setup
Ess.start(this);
mySoundA=new Channel();
mySoundA.initBuffer(mySoundA.frames(250));
mySoundA.wave(Ess.SINE,960,.75);
pshift=0;
}
void parseRoombaSensors() {
if( !roombacomm.cliffLeft() ) pshift++;
if( !roombacomm.cliffFrontLeft() ) pshift++;
if( !roombacomm.cliffRight() ) pshift -- ;
if( !roombacomm.cliffFrontRight() ) pshift -- ;
if( !roombacomm.wheelDropLeft() ) pshift++;
if( !roombacomm.wheelDropRight() ) pshift -- ;
if( !roombacomm.wheelDropLeft() &&
!roombacomm.wheelDropRight() ) {
pshift = 0;
mySoundA.stop();
}
else if( roombacomm.bump() ) // bump to start playing
mySoundA.play(Ess.FOREVER);
}
void channelLoop(Channel ch) {
if( pshift != 0 ) {
mySoundA.rate(1.0 + pshift*0.01);
pshift = 0;
}
}

