HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"A Waba-Powered Palm Pilot Robot"
Vol. 6, Issue 12, p. 64

	


Listing 1

package com.trexlabs.worf.robot;


import com.trexlabs.worf.sv203.*;
import com.trexlabs.worf.ir.*;
import com.trexlabs.worf.servo.*;


import waba.ui.*;
import waba.fx.*;
import waba.io.*;


/**
 * An example program using WORF to make your robot dance while it
 * plays a catchy tune.
 *
 * @author James Caple Copyright (C) 2001, All Rights Reserved
 */


public class WORFHatDance extends MainWindow {


    private Button begin;
    private SV203 board;
    private PPRKServo servos;


    public WORFHatDance() {
        begin = new Button("Let's Dance!");
        begin.setRect(50, 85, 59, 20);
        add(begin);


        // WORF Setup
        board = new SV203();
        servos = new PPRKServo(board);
    }


    /**
     * Draw about Strings.
     * @param Graphics
     * @return void
     */
    public void onPaint( Graphics g ) {
        g.setColor(0, 0, 0);
        g.drawText("WORF Hat Dance Example", 0, 0);
        g.drawText("Copyright (C) 2001, James Caple", 0, 10);
        g.drawText("http://worf.sourceforge.net", 0, 20);
    }



    public void onEvent(Event evt) {
        if (evt.type == ControlEvent.PRESSED && evt.target == begin) {
            getYourGrooveOn();
        }
    }


    private void getYourGrooveOn() {
        // Swing to your right
        servos.turnRight((byte)3);


        Sound.tone(3000, 500);
        Sound.tone(2900, 200);
        Sound.tone(3000, 200);
        Sound.tone(2600, 200);
        Sound.tone(2500, 200);
        Sound.tone(2600, 200);
        Sound.tone(2100, 200);
        Sound.tone(2000, 200);
        Sound.tone(2100, 200);
        Sound.tone(1500, 500);


        // Swing to your left
        servos.turnLeft((byte)3);


        Sound.tone(1300, 200);
        Sound.tone(1400, 200);
        Sound.tone(1500, 200);
        Sound.tone(1700, 200);
        Sound.tone(1900, 200);
        Sound.tone(2000, 200);
        Sound.tone(2300, 200);
        Sound.tone(2500, 200);
        Sound.tone(2700, 200);
        Sound.tone(2300, 500);


        // Swing to your right
        servos.turnRight((byte)3);


        Sound.tone(2700, 200);
        Sound.tone(2600, 200);
        Sound.tone(2700, 200);
        Sound.tone(2300, 200);
        Sound.tone(2200, 200);
        Sound.tone(2300, 200);
        Sound.tone(1900, 200);
        Sound.tone(1800, 200);
        Sound.tone(1900, 200);
        Sound.tone(1500, 500);


        // Swing to your right
        servos.turnLeft((byte)3);


        Sound.tone(3000, 200);
        Sound.tone(3000, 200);
        Sound.tone(3000, 200);
        Sound.tone(3300, 200);
        Sound.tone(3000, 200);
        Sound.tone(2700, 200);
        Sound.tone(2500, 200);
        Sound.tone(2200, 200);
        Sound.tone(2000, 500);


        Sound.tone(4000, 100);


        // Cha cha cha!
        servos.stop();
        servos.turnRight((byte)3);
        servos.turnLeft((byte)3);
        servos.turnRight((byte)3);
        servos.stop();
    }


}

  
 
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.