Page 220 - Hacking Roomba
P. 220
Chapter 10 — Using Roomba as an Input Device 201
You probably want to use the simpler serial tether rather than the Bluetooth adapter for the
alarm clock. Some computers may power down their Bluetooth interface if it’s idle. Regular serial
ports don’t have that problem.
Listing 10-4: RoombAlarmClock
String wakeupTime = “6/20/06 07:48 am”;
Date wakeupDate = null;
boolean alarm = false;
int snoozeSecs = 60 * 9; // nine minutes
String radioCmd[] = {“osascript”, “-e”,
“tell app \”iTunes\” to playpause”};
void setup() {
framerate(1);
roombacommSetup();
DateFormat
df=DateFormat.getDateTimeInstance(DateFormat.SHORT,
DateFormat.SHORT);
try { wakeupDate = df.parse(wakeupTime); }
catch( Exception e ) { println(“error:”+e); }
println(“wakeupTime: “+wakeupDate);
}
void draw() {
if( roombacomm == null ) return;
parseRoombaSensors();
updateRoombaState();
Date now = new Date();
if( now.compareTo( wakeupDate ) > 0 )
playAlarm();
}
void playAlarm() {
alarm = true;
println(“playAlarm”);
int song[] = { 78,4, 77,4, 76,4, 75,4,
74,4, 73,4, 72,4, 71,4,
70,4, 69,4, 70,4, 71,4 };
roombacomm.createSong(5,song);
roombacomm.playSong(5); // play rude song
for( int i=0; i<5; i++ ) { // and shudder a little
roombacomm.spinLeftAt(75); roombacomm.pause( 100 );
roombacomm.spinRightAt(75); roombacomm.pause( 100 );
roombacomm.stop();
}
}
void runRadioCmd() {
try {
Continued