Using the Engfoot library
The first step to using the Engfoot library is to create a new Engfoot object:
Engfoot engfoot = new Engfoot();
With the engfoot
reference, one can access the following methods:
class Engfoot | Description |
---|---|
connect() | Connects to the first port that the library finds |
connect(String port) | Connects to the port in the string, for example "COM14" |
getSerialPorts() | Returns an array of available ports. An empty array is returned if there are no ports available |
For example:
Engfoot engfoot = new Engfoot();
String[] ports = engfoot.getSerialPorts();
EngduinoInterface engduino = engfoot.connect(ports[0]); // this is the same as engfoot.connect();
class EngduinoInterface | Description |
---|---|
addButtonHandler(ButtonHandler handler) | Adds a handler that gets called every time the button state changes |
addTemperatureHandler(ValueChangeHandler<Float> handler) | Adds a handler for temperature changes |
addAccelerometerHandler(ValueChangeHandler<Double> handler) | Adds a handler for accelerometer changes |
addLightSensorHandler(ValueChangeHandler<Float> handler) | Adds a handler for light sensor changes |
addMagnetometerHandler(ValueChangeHandler<float[]> handler) | Adds a handler for magnetometer changes, may require some calibration |
createLightCommand() | Returns an instance of LightCommandBuilder so you can string commands together controlling the LEDs of the Engduino |
disconnect() | Closes the serial port, returning a success boolean |
One does not simply construct EngduinoInterface
by yourself.
You receive a reference when you call the connect
method in the previous example.
ValueChangeHandler<...>
is an interface that you must implement like the following example:
engduino.addLightSensorHandler(new ValueChangeHandler<Float>() {
public void onChange(Value<Float> value) {
System.out.println(value.get());
}
});
How to use LightCommandBuilder
EngduinoInterface engduino;
engduino.createLightCommand().setLED(14, new ColorSettings(true, Color.yellow)).build().execute();
This turns LED number 14 on with yellow colour. You can add additional commands:
engduino.createLightCommand()
.setLED(14, new ColorSettings(true, Color.yellow))
.setLED(13, new ColorSettings(true 255, 100, 200))
.build().execute();