Saturday Sep 22, 2012

Tinkerforge Rotation/LCD & JavaFX Plans

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.

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« September 2012 »
SunMonTueWedThuFriSat
      
2
16
19
      
Today