summaryrefslogtreecommitdiff
path: root/roombacomm-client/src/processing-examples/roombaring
diff options
context:
space:
mode:
authorIdo Hadanny <ido.hadanny@gmail.com>2011-09-22 21:30:13 +0300
committerIdo Hadanny <ido.hadanny@gmail.com>2011-09-22 21:30:13 +0300
commit53b947df484159f5934898ba6c0aa69a9c869007 (patch)
tree189d5903a67765c390de8f1e3423e6b80cde57d1 /roombacomm-client/src/processing-examples/roombaring
parent654ca6d59e99b5e72b05dfb917bc5888c4ba6b1b (diff)
added stuff
Diffstat (limited to 'roombacomm-client/src/processing-examples/roombaring')
-rw-r--r--roombacomm-client/src/processing-examples/roombaring/roombaring.pde54
1 files changed, 54 insertions, 0 deletions
diff --git a/roombacomm-client/src/processing-examples/roombaring/roombaring.pde b/roombacomm-client/src/processing-examples/roombaring/roombaring.pde
new file mode 100644
index 0000000..74aee3d
--- /dev/null
+++ b/roombacomm-client/src/processing-examples/roombaring/roombaring.pde
@@ -0,0 +1,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();