Tinkerforge Rotation/LCD & JavaFX Plans

Posted by Geertjan on Oracle Blogs See other posts from Oracle Blogs or by Geertjan
Published on Sat, 22 Sep 2012 12:07:55 +0000 Indexed on 2012/09/22 15:44 UTC
Read the original article Hit count: 351

Filed under:
The first time I integrated two Tinkerforge bricklets, the day before yesterday, was pretty cool:
import com.tinkerforge.BrickMaster;
import com.tinkerforge.BrickletLCD20x4;
import com.tinkerforge.BrickletRotaryPoti;
import com.tinkerforge.IPConnection;
import java.util.Calendar;

public class TFConnectionDemo {

    private static final String HOST = "localhost";
    private static final int PORT = 4223;
    private static final String MASTERBRICKUID = "somethingabc";
    private static final String LCDUID = "somethingabc";
    private static final String ROTIUID = "somethingabc";
    private static IPConnection ipc;
    private static BrickMaster master = new BrickMaster(MASTERBRICKUID);
    private static BrickletLCD20x4 lcd = new BrickletLCD20x4(LCDUID);
    private static BrickletRotaryPoti poti = new BrickletRotaryPoti(ROTIUID);

    public static void main(String[] args) {

        try {
            ipc = new IPConnection(HOST, PORT);
            ipc.addDevice(master);
            ipc.addDevice(lcd);
            ipc.addDevice(poti);
            poti.setPositionCallbackPeriod(50);
            poti.addListener(new BrickletRotaryPoti.PositionListener() {
                @Override
                public void position(short position) {
                    lcd.clearDisplay();
                    Calendar cal = Calendar.getInstance();
                    lcd.writeLine((short) 0, (short) 0, cal.getTime().toString());
                    lcd.writeLine((short) 1, (short) 0, "Rotation: " + position);
                }
            });
        } catch (Exception e) {
        }
    }
    
}

The result is that the display text in the LCD bricklet changes while I turn the rotation bricklet:

Now imagine that you have some JavaFX charts and, while you turn the rotation bricklet (i.e., the dial thing that I'm turning above), the values of the charts change. That would be pretty cool because you'd be able to animate the JavaFX charts by rotating an object externally, i.e., without even touching the keyboard. That would be pretty cool to see and shouldn't be hard to implement.

© Oracle Blogs or respective owner

Related posts about /NetBeans IDE