import processing.serial.*; //first import serial library Serial myPort; //myPort is our serial PFont font; //create font int value = 0; int n1, n2, n3, n4, n5, n6, n7, n8; void setup() { font = loadFont("OCRAExtended-99.vlw"); //load font background(25); //background color is 25 (255 = white) (0 = black) textFont(font, 20); //font is font and size is 20 textAlign(CENTER, CENTER); //text is at center(x) and center(y) size(640, 640); //window size is 640x640 pixels myPort = new Serial(this, "COM3", 9600); //open serial port in COM3 } void draw() { drawRects(); //i writed void that draws the squares writeNums(); //another void to write numbers println(mouseX, "/" ,mouseY); //print mouse position checkMouse(); //void to check, if mouse clicked and where it has clicked myPort.write(value); //write value to Arduino delay(20); } void drawRects() { //draw squares fill(255); //make squares white for(int x = 0; x < 640;) { //this for function is drawing squares to x(x position) //plus x position with 80 while x is over 640 float rectcolor = map(x, 0, 640, 100, 255); //this makes gradient fill to squares fill(rectcolor); //this fills squares with gradient fill rect(x,0,80,80); //draw square x = x + 80; //plus x position with 80 while x is over 640 } } void checkMouse() { //check if mouse is clicked and check where itīs clicked if((mouseX > 0) && (mouseX < 80)) { if((mouseY > 0) && (mouseY < 80)) { if(mousePressed) { value = 1; } } } if((mouseX > 80) && (mouseX < 160)) { if((mouseY > 0) && (mouseY < 80)) { if(mousePressed) { value = 2; } } } if((mouseX > 160) && (mouseX < 240)) { if((mouseY > 0) && (mouseY < 80)) { if(mousePressed) { value = 4; } } } if((mouseX > 240) && (mouseX < 320)) { if((mouseY > 0) && (mouseY < 80)) { if(mousePressed) { value = 8; } } } if((mouseX > 320) && (mouseX < 400)) { if((mouseY > 0) && (mouseY < 80)) { if(mousePressed) { value = 16; } } } if((mouseX > 400) && (mouseX < 480)) { if((mouseY > 0) && (mouseY < 80)) { if(mousePressed) { value = 32; } } } if((mouseX > 480) && (mouseX < 560)) { if((mouseY > 0) && (mouseY < 80)) { if(mousePressed) { value = 64; } } } if((mouseX > 560) && (mouseX < 640)) { if((mouseY > 0) && (mouseY < 80)) { if(mousePressed) { value = 128; } } } } void writeNums() { //write numbers in square n1 = 0; n2 = 0; n3 = 0; n4 = 0; n5 = 0; n6 = 0; n7 = 0; n8 = 0; switch(value) { case 1: n1 = 255; break; case 2: n2 = 255; break; case 4: n3 = 255; break; case 8: n4 = 255; break; case 16: n5 = 255; break; case 32: n6 = 255; break; case 64: n7 = 255; break; case 128: n8 = 255; break; } textFont(font, 45); //visualize font colors (if led is on, font is colorized with led color) fill(n1, 0, 0); text(1, 40, 40); fill(n2, 0, 0); text(2, 120, 40); fill(0, n3, 0); text(3, 200, 40); fill(0, n4, 0); text(4, 280, 40); fill(n5, n5, 0); text(5, 360, 40); fill(n6, n6, 0); text(6, 440, 40); fill(0, 0, n7); text(7, 520, 40); fill(0, 0, n8); text(8, 600, 40); } //and itīs ready!