1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
//
// roombaring --
//
// 2006, Tod E. Kurt, tod@todbot.com, http://roombahacking.com/
//
import roombacomm.*;
String rtttl = "tron:d=4,o=5,b=100:8f6,8c6,8g,e,8p,8f6,8c6,8g,8f6,8c6,8g,e,8p,8f6,8c6,8g,e.,2d";
String roombacommPort = "/dev/cu.KeySerial1";
//String roombacommPort = "/dev/cu.BlueRadios-COM0-1";
RoombaCommSerial roombacomm = new RoombaCommSerial();
if( ! roombacomm.connect( roombacommPort ) ) {
println("couldn't connect. goodbye."); System.exit(1);
}
println("Roomba startup");
roombacomm.startup();
roombacomm.control();
roombacomm.pause(50);
ArrayList notelist = RTTTLParser.parse( rtttl );
int songsize = notelist.size();
// if within the size of a roomba song, make the song, then play
if( songsize <= 16 ) {
println("creating a song with createSong()");
int notearray[] = new int[songsize*2];
int j=0;
for( int i=0; i< songsize; i++ ) {
Note note = (Note) notelist.get(i);
int sec64ths = note.duration * 64/1000;
notearray[j++] = note.notenum;
notearray[j++] = sec64ths;
}
roombacomm.createSong( 1, notearray );
roombacomm.playSong( 1 );
}
// otherwise, try to play it in realtime
else {
println("playing song in realtime with playNote()");
int fudge = 20;
for( int i=0; i< songsize; i++ ) {
Note note = (Note) notelist.get(i);
int duration = note.duration;
int sec64ths = duration*64/1000;
if( sec64ths < 5 ) sec64ths = 5;
if( note.notenum != 0 )
roombacomm.playNote( note.notenum, sec64ths );
roombacomm.pause( duration + fudge );
}
}
System.out.println("Disconnecting");
roombacomm.disconnect();
|