/************************************* MICRODEV.GR SENSOR BOARD - ARDUINO MEGA 2560 Virtual Instrument Panel (C) PANOS PAPAZOGLOU 2023 **************************************/ //*********************************************************************************** //Import Library for serial communication //*********************************************************************************** import processing.serial.*; Serial myPort; float P4=PI/4; int k=0; void setup() { size(1850,1200); surface.setTitle("Microdev.gr - Virtual Instruments"); //*********************************************************************************** //Select correct port number (e.g. COM8, COM12). Use device manager or Arduino IDE //for finding the assigned port by OS //*********************************************************************************** myPort = new Serial(this, "COM15", 9600); //myPort = new Serial(this, Serial.list()[0], 9600); } void draw() { //*********************************************************************************** //Read a line from serial port //*********************************************************************************** try { String inString=myPort.readStringUntil('\n'); //*********************************************************************************** //If data exist... //*********************************************************************************** if (inString!=null) { //*********************************************************************************** //Split received string using the character "." //*********************************************************************************** String[] num=splitTokens(inString,"/"); int[] metr = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; String[] mtext={"POT-A:", "POT-B:", "POT-C:","JOY-Y:", "JOY-X:", "LM35:", "LDR:", "A.TMP:", "SND:", "NC:", "D.TEMP:", "D.HUM:", "PIR:", "Dist:"}; println("---> ",k," <---"); k++; for(int i=0;i>>>>>>>>>>>>> ",f); println(mtext[i],metr[i]); } float lm35=(metr[5]*4.88)/10; float fenya=((float)metr[7]/1023)*5; float r=(5-fenya)/fenya*4700; float atemp=( 1/(log(r/10000) /3950 + 1/(25+273.15))-273.15); float dtemp=metr[10]/100; float dhumi=metr[11]/100; background(#939393); instrument(10, 20, 300, 0, 1023, 0, metr[3], #000000, #ffffff, #ffffff, 10,25, "J-Y",35); instrument(500, 20, 300, 0, 1023, 0, metr[4], #000000, #ffffff, #ffffff, 10,25, "J-X",35); instrument(1000, 20, 300, 0, 50, 1, lm35, #000000, #ffffff, #ffffff, 10,25, "LM35",35); instrument(10, 400, 300, 0, 1023, 1, metr[6], #000000, #ffffff, #ffffff, 10,25, "LDR",35); instrument(500, 400, 300, 0, 1023, 1, atemp, #000000, #ffffff, #ffffff, 10,25, "A.Temp",35); instrument(1000, 400, 300, 0, 50, 1, dtemp, #ffffff, #000000, #ff0000, 10,25, "D.TEMP",35); instrument(10, 800, 300, 0, 100, 1, dhumi, #ffffff, #000000, #ff0000, 10,25, "D.HUMI",35); bar(1500,120,300,50,0,1023,metr[8], #000000, #ffff00, 5,"SND",35); bar(1500,370,300,50,0,1,metr[12],#000000, #00ffff, 5,"PIR",35); bar(1500,650,300,50,0,400,metr[13], #000000, #ffffff, 5,"Dist",35); bar(500,950,300,50,0,255,metr[0],#0000ff, #ff0000, 5,"RED",35); bar(900,950,300,50,0,255,metr[1],#0000ff, #00ff00, 5,"GREEN",35); bar(1300,950,300,50,0,255,metr[2],#0000ff, #0000ff, 5,"BLUE",35); fill(metr[0],metr[1],metr[2]); circle(1700,970,100); fill(0); text("RGB",1670,1060); fill(0,0,128); textSize(30); text("MICRODEV.GR - Panos Papazoglou", width-450,height-20); } }//try catch (Exception e) { println("Error..."); } } void bar(int xstart, int ystart, int w, int h, int kmin, int kmax, float metr, int RGBmetr, int RGBbar, int NW, String t, int ts) { //zones, RGBfill, LW, //content strokeWeight(NW); stroke(color(#000000)); fill(color(#939393)); rect(xstart, ystart, w,h); //stroke(color(RGBbar)); strokeWeight(1); fill(color(RGBbar)); float th=map(metr,kmin,kmax,0, 100); rect(xstart, ystart, w*th/100,h); //digital measurement textSize(ts); fill(color(RGBmetr)); //String textmetr=nf(th,0,2)+"%"; //text(textmetr, xstart+w*0.5, ystart+h*1.6); text(int(metr), xstart+w*0.5, ystart+h*1.6); text(t,xstart, ystart-30); } void instrument(int xstart, int ystart, int diam, int kmin, int kmax, int zones, float metr, int RGBfill, int RGBmetr, int RGBpointer, int LW, int NW, String t, int ts) { //draw upper semi-circle float x=xstart+(diam*1.5)/2; float y=ystart+(diam*1.5)/2; stroke(color(#939393)); fill(color(RGBfill)); arc(x, y, diam*0.95, diam*0.95, PI, 2*PI); //draw frame strokeWeight(NW); fill(color(RGBfill)); rect((x-(diam*1.1)/2), (y-(diam*1.1)/2)-2*LW, diam*1.1,diam); stroke(color(#a5a5a5)); rect((x-(diam*1.3)/2), (y-(diam*1.3)/2)-2*LW, diam*1.3,diam); //draw full color zones if (zones==1) { stroke(0,0,255); //blue arc(x,y,diam,diam,PI,PI+P4); stroke(0,255,0); //green arc(x,y,diam,diam,5*(P4), 6*(P4)); stroke(255,255,0); //yellow arc(x,y,diam,diam,6*(P4), 7*(P4)); stroke(255,0,0); //red arc(x,y,diam,diam,7*(P4), 8*(P4)); } //draw blue scale zones if (zones==2) { stroke(0,0,63); arc(x,y,diam,diam,PI,PI+QUARTER_PI); stroke(0,0,127); arc(x,y,diam,diam,5*(P4), 6*(P4)); stroke(0,0,191); arc(x,y,diam,diam,6*(P4), 7*(P4)); stroke(0,0,255); arc(x,y,diam,diam,7*(P4), 8*(P4)); } //instrument label textSize(ts); fill(0,0,0); text(t, (x-((diam/2)*0.3)), y+(diam/2)*0.9);//(y-((diam/2)*0.2))); //draw ticks stroke(255); strokeWeight(5); for(int ith=180;ith<360;ith+=4) { float rang=radians(ith); float fx=x+(diam/2)*cos(rang); float fy=y+(diam/2)*sin(rang); point(fx,fy); } //draw 0% fill(0,255,0); textSize(ts*0.8); text("0%", x+((diam*1.1)/2)*cos(radians(180)), y+(diam*0.08)); //draw 50% fill(0,100,255); textSize(ts*0.8); text("50%", x-(diam*0.06), y+((diam*1.1)/2)*sin(radians(270))); //draw 100% fill(255,50,0); textSize(ts*0.8); text("100%", x+((diam*0.8)/2)*cos(radians(360)), y+(diam*0.08)); //draw pointer stroke(color(RGBpointer)); float th=map(metr,kmin,kmax,PI, 2*PI); strokeWeight(LW); line(x, y,x+(diam/2)*cos(th),y+(diam/2)*sin(th)); //digital measurement textSize(diam*0.2); fill(color(RGBmetr)); String textmetr=nf(metr,0,2); text(textmetr, (x-((diam/2)*0.3)), (y+((diam/2)*0.4))); }