///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS com.fazecast:jSerialComm:2.10.2 //SOURCES helper/PixelBlazeOutputExpanderHelper.java import helper.PixelBlazeOutputExpanderHelper; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; public class PboeLedMatrix { private static final int CHANNEL_MATRIX = 1; private static final int BYTES_PER_PIXEL = 3; private static final int NUMBER_OF_LEDS_MATRIX = 8 * 8; public static void main(String[] args) throws Exception { PixelBlazeOutputExpanderHelper helper = new PixelBlazeOutputExpanderHelper("/dev/ttyS0"); helper.sendAllOff(CHANNEL_MATRIX, NUMBER_OF_LEDS_MATRIX); BufferedImage bImage = ImageIO.read(new File("heart_8x8.png")); if (bImage.getWidth() != 8 && bImage.getHeight() != 8) throw new IllegalStateException("Image is not 8x8!"); bImage = rotateImage(bImage, 90); byte[] pixelsRgb = new byte[NUMBER_OF_LEDS_MATRIX * BYTES_PER_PIXEL]; int i = 0; for (int x = 0; x < bImage.getWidth(); x++) { for (int y = 0; y < bImage.getHeight(); y++) { int rgb = bImage.getRGB(x, y); Color color = new Color(rgb, false); color = color.darker().darker().darker().darker().darker().darker().darker().darker().darker().darker(); int blue = color.getBlue(); int green = color.getGreen(); int red = color.getRed(); pixelsRgb[(i * BYTES_PER_PIXEL)] = (byte) red; pixelsRgb[(i * BYTES_PER_PIXEL) + 1] = (byte) green; pixelsRgb[(i * BYTES_PER_PIXEL) + 2] = (byte) blue; i++; } } helper.sendColors(CHANNEL_MATRIX, pixelsRgb, false); Thread.sleep(5000); helper.sendAllOff(CHANNEL_MATRIX, NUMBER_OF_LEDS_MATRIX); //Thread.sleep(100); helper.closePort(); } private static BufferedImage rotateImage(BufferedImage buffImage, double angle) { double radian = Math.toRadians(angle); double sin = Math.abs(Math.sin(radian)); double cos = Math.abs(Math.cos(radian)); int width = buffImage.getWidth(); int height = buffImage.getHeight(); int nWidth = (int) Math.floor((double) width * cos + (double) height * sin); int nHeight = (int) Math.floor((double) height * cos + (double) width * sin); BufferedImage rotatedImage = new BufferedImage(nWidth, nHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = rotatedImage.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); graphics.translate((nWidth - width) / 2, (nHeight - height) / 2); // rotation around the center point graphics.rotate(radian, (double) (width / 2), (double) (height / 2)); graphics.drawImage(buffImage, 0, 0, null); graphics.dispose(); return rotatedImage; } }