import java.awt.*; import java.awt.image.*; import processing.serial.*; // using 82 RGB LEDs static final int led_num_x = 30; static final int led_num_y = 18; static final int leds[][] = new int[][] { {28,17}, {27,17}, {26,17}, {25,17}, {24,17}, {23,17}, {22,17}, {21,17}, {20,17}, {19,17}, {18,17}, // Bottom edge, left half {29,16}, {29,15}, {29,14}, {29,13}, {29,12}, {29,11}, {29,10}, {29,9}, {29,8}, {29,7}, {29,6}, {29,5}, {29,4}, {29,3}, {29,2}, {29,1},// Right edge {28,0}, {27,0}, {26,0}, {25,0}, {24,0}, {23,0}, {22,0}, {21,0}, {20,0}, {19,0}, {18,0}, {17,0}, {16,0}, {15,0}, {14,0}, {13,0}, {12,0}, {11,0}, {10,0}, {9,0}, {8,0}, {7,0}, {6,0}, {5,0}, {4,0}, {3,0}, {2,0}, {1,0}, // Top edge {0,1}, {0,2}, {0,3}, {0,4}, {0,5}, {0,6}, {0,7}, {0,8}, {0,9}, {0,10}, {0,11}, {0,12}, {0,13}, {0,14}, {0,15}, {0,16},// Left edge {11,17}, {10,17}, {9,17}, {8,17}, {7,17}, {6,17}, {5,17}, {4,17}, {3,17}, {2,17}, {1,17} // Bottom edge, left half }; static final short fade = 70; static final int minBrightness = 120; // Preview windows int window_width; int window_height; int preview_pixel_width; int preview_pixel_height; int[][] pixelOffset = new int[leds.length][256]; // RGB values for each LED short[][] ledColor = new short[leds.length][3], prevColor = new short[leds.length][3]; byte[][] gamma = new byte[256][3]; byte[] serialData = new byte[ leds.length * 3 + 2]; int data_index = 0; //creates object from java library that lets us take screenshots Robot bot; // bounds area for screen capture Rectangle dispBounds; // Monitor Screen information GraphicsEnvironment ge; GraphicsConfiguration[] gc; GraphicsDevice[] gd; Serial port; void setup() { int[] x = new int[16]; int[] y = new int[16]; // ge - Grasphics Environment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); // gd - Grasphics Device gd = ge.getScreenDevices(); DisplayMode mode = gd[0].getDisplayMode(); dispBounds = new Rectangle(0, 0, mode.getWidth(), mode.getHeight()); // Preview windows window_width = mode.getWidth()/5; window_height = mode.getHeight()/5; preview_pixel_width = window_width/led_num_x; preview_pixel_height = window_height/led_num_y; // Preview window size size(window_width, window_height); //standard Robot class error check try { bot = new Robot(gd[0]); } catch (AWTException e) { println("Robot class not supported by your system!"); exit(); } float range, step, start; for (int i=0; i> 24) & 0xff) * (255 - fade) + prevColor[i][0] * fade) >> 8); ledColor[i][1] = (short)(((( g >> 16) & 0xff) * (255 - fade) + prevColor[i][1] * fade) >> 8); ledColor[i][2] = (short)(((( b >> 8) & 0xff) * (255 - fade) + prevColor[i][2] * fade) >> 8); serialData[data_index++] = (byte)ledColor[i][0]; serialData[data_index++] = (byte)ledColor[i][1]; serialData[data_index++] = (byte)ledColor[i][2]; float preview_pixel_left = (float)dispBounds.width /5 / led_num_x * leds[i][0] ; float preview_pixel_top = (float)dispBounds.height /5 / led_num_y * leds[i][1] ; color rgb = color(ledColor[i][0], ledColor[i][1], ledColor[i][2]); fill(rgb); rect(preview_pixel_left, preview_pixel_top, preview_pixel_width, preview_pixel_height); } if (port != null) { port.setDTR(true); // wait for Arduino to send data for (;;) { if (port.available() > 0) { int inByte = port.read(); if (inByte == 'y') break; } } port.write(serialData); // Issue data to Arduino } // Benchmark, how are we doing? println(frameRate); arraycopy(ledColor, 0, prevColor, 0, ledColor.length); }