use of com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor in project robo4j by Robo4J.
the class AdafruitBiColor24BackpackExample method main.
public static void main(String[] args) throws Exception {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
InputStream settings = AdafruitBiColor24BackpackExample.class.getClassLoader().getResourceAsStream("bargraph24example.xml");
RoboContext ctx = new RoboBuilder().add(settings).build();
ctx.start();
RoboReference<DrawMessage> barUnit = ctx.getReference("bargraph");
DrawMessage clearMessage = new DrawMessage(BackpackMessageCommand.CLEAR);
AtomicInteger position = new AtomicInteger();
executor.scheduleAtFixedRate(() -> {
if (position.get() > BiColor24BarDevice.MAX_BARS - 1) {
position.set(0);
}
barUnit.sendMessage(clearMessage);
barUnit.sendMessage(new DrawMessage(BackpackMessageCommand.PAINT, new short[] { (short) position.getAndIncrement() }, new short[] { 0 }, new BiColor[] { BiColor.getByValue(position.get() % 3 + 1) }));
}, 2, 1, TimeUnit.SECONDS);
System.out.println("Press enter to quit\n");
System.in.read();
executor.shutdown();
ctx.shutdown();
}
use of com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor in project robo4j by Robo4J.
the class AdafruitBiColorMatrix8x8BackpackExample method main.
public static void main(String[] args) throws Exception {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
InputStream settings = AdafruitBiColorMatrix8x8BackpackExample.class.getClassLoader().getResourceAsStream("matrix8x8example.xml");
RoboContext ctx = new RoboBuilder().add(settings).build();
ctx.start();
System.out.println("State after start:");
System.out.println(SystemUtil.printStateReport(ctx));
RoboReference<DrawMessage> matrixUnit = ctx.getReference("matrix");
AtomicInteger position = new AtomicInteger();
executor.scheduleAtFixedRate(() -> {
if (position.get() > 7) {
position.set(0);
}
matrixUnit.sendMessage(DrawMessage.MESSAGE_CLEAR);
matrixUnit.sendMessage(new DrawMessage(BackpackMessageCommand.PAINT, new short[] { (short) position.get() }, new short[] { (short) position.getAndIncrement() }, new BiColor[] { BiColor.getByValue(position.get() % 3 + 1) }));
}, 2, 1, TimeUnit.SECONDS);
System.out.println("Press enter to quit\n");
System.in.read();
executor.shutdown();
ctx.shutdown();
}
Aggregations