Search in sources :

Example 1 with BiColor

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();
}
Also used : BiColor(com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStream(java.io.InputStream) RoboContext(com.robo4j.RoboContext) RoboBuilder(com.robo4j.RoboBuilder)

Example 2 with BiColor

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();
}
Also used : BiColor(com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStream(java.io.InputStream) RoboContext(com.robo4j.RoboContext) RoboBuilder(com.robo4j.RoboBuilder)

Aggregations

RoboBuilder (com.robo4j.RoboBuilder)2 RoboContext (com.robo4j.RoboContext)2 BiColor (com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor)2 InputStream (java.io.InputStream)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2