Segundo applet, cierre y botones transparentes en Processing 3

A todos los KU. Mi primer post, por favor no juzgues estrictamente.

Era necesario trabajar para leer visualmente el estado del equipo y, si fuera necesario, reiniciar el criocompresor de forma remota. A la mano estaba Arduino UNO, se compr贸 un sensor de luz ambiental para 茅l, hasta ahora hay 2 rel茅s y 2 solenoides a 12 V (no es el punto). En el futuro, este negocio estar谩 cubierto de sensores de temperatura, humedad y presi贸n, pero hasta ahora no est谩 listo.

La raz贸n para escribir la publicaci贸n es que hab铆a muy poca informaci贸n en Internet sobre las capacidades de Processing 3, especialmente en la parte del idioma ruso. Espero que algunas teteras como yo sean 煤tiles alg煤n d铆a para no ser tan est煤pido como yo durante la semana pasada.

El boceto para Arduino es tan simple como tres rublos: al recibir ciertos valores del puerto com, el volcado establece el valor en los pines y escribe la respuesta en el puerto com, tambi茅n mide la iluminaci贸n y tambi茅n informa al respecto. En el futuro, se ampliar谩.

Bosquejo Arduino:

#include <Wire.h> #include <BH1750.h> int val; BH1750 lightMeter; void setup() { Serial.begin(9600); lightMeter.begin(); Serial.println("Running..."); pinMode (7, OUTPUT); pinMode(6, OUTPUT); digitalWrite(7, HIGH); digitalWrite(6, HIGH); } void loop() { uint16_t lux = lightMeter.readLightLevel(); if (Serial.available()) { val = Serial.read(); if (val == '0') { digitalWrite(7, HIGH); digitalWrite(6, HIGH); Serial.println("  "); } if (val == '1') { digitalWrite(7, HIGH); digitalWrite(6, LOW); Serial.println(" 1 "); } if (val == '2') { digitalWrite(7, LOW); digitalWrite(6, HIGH); Serial.println("  2"); } if (val == '3') { digitalWrite(7, LOW); digitalWrite(6, LOW); Serial.println("  "); } if (val == '4') { if (lux >= 800) { Serial.print("Light: "); Serial.print(lux); Serial.println(" lx   "); } else { Serial.print("Light: "); Serial.print(lux); Serial.println(" lx  !!!!!!!"); } } } } 

Esto, creo, es obvio, pero debido al hecho de que otras personas usar谩n la funcionalidad de mi Pribluda en el futuro, quer铆a escribir una GUI simple pero comprensible. La elecci贸n recay贸 en el procesamiento, ya que anteriormente estaba familiarizado con el IDE Arduino, que, a su vez, se cre贸 sobre la base del procesamiento.

El applet usa la biblioteca ControlP5 para representar los controles.

Personalmente, tuve problemas con la implementaci贸n y la b煤squeda de informaci贸n sobre las siguientes cosas: 1) iniciar la segunda ventana desde la aplicaci贸n, 2) cerrar la segunda ventana, pero para que la ventana principal siga funcionando, 3) por diversi贸n: establecer im谩genes como fondo y botones, botones transl煤cidos.

Entonces, el boceto de procesamiento:

Listado de c贸digo
 import processing.serial.*; import controlP5.*; import java.util.Date; Serial port; Textfield recived; Textfield recived1; Textfield recived2; Textfield recived3; Textfield recived4; Textfield recived5; String val; String data; String DateTab; String Dat; int data2=0; String time; Button vyvod; PrintWriter output; Table table2; int i=0; ControlP5 cp5; ControlP5 ax; PFont font; PFont font2; String[] args = {"YourSketchNameHere"}; SecondApplet sa; PImage fon; PImage fon2; PImage titlebaricon; //     void setup() { titlebaricon = loadImage("data/myicon.png"); surface.setIcon(titlebaricon); surface.setTitle(" "); //     ))) printArray(Serial.list()); port = new Serial(this, "/dev/ttyUSB0", 9600); // com  ( Ubuntu,  Windows  //com port) cp5 = new ControlP5(this); font = createFont("Arial", 20); //  fon = loadImage("data/phil.bmp"); //     fon2 = loadImage("data/fon2.bmp"); /*        void settings()*/ PImage img; img = loadImage("data/image1.bmp"); // -     "data"  image(img, 0, 0); tint(0, 255, 0, 126); //  - 50%      image(img, 50, 0); PImage img2; img2 = loadImage("data/image2.bmp"); image(img2, 0, 0); image(img2, 50, 0); //       // tint()       . PImage img3; //       . img3 = loadImage("data/image3.bmp"); image(img3, 0, 0); image(img3, 50, 0); PImage img4; img4 = loadImage("data/image4.bmp"); image(img4, 0, 0); image(img4, 50, 0); PImage img5; img5 = loadImage("data/imagezapros.bmp"); image(img5, 0, 0); image(img5, 50, 0); PImage img6; img6 = loadImage("data/temper.bmp"); image(img6, 0, 0); image(img6, 50, 0); cp5.addButton("Relay_1") .setSize (100, 50) .setPosition(50, 50) .setFont(font) .setImage(img) .setLabel(" 1"); cp5.addButton("Relay_2") .setSize (100, 50) .setPosition(250, 50) .setFont(font) .setImage(img2) .setLabel(" 2"); cp5.addButton("Relay_ON") .setSize (300, 50) .setPosition(50, 120) .setFont(font) .setLabel(" ") .setImage(img3); cp5.addButton("Relay_OFF") .setSize (300, 50) .setPosition(50, 190) .setFont(font) .setLabel(" ") .setImage(img4); cp5.addButton("Zapros_sostoyaniya") .setSize (300, 50) .setPosition(50, 260) .setFont(font) .setLabel(" ") .setImage(img5); recived=cp5.addTextfield(" ") .setSize(380,100) .setPosition(10, 340) .setColorValueLabel(0) .setFont(font) .setColorBackground(color(255, 255, 255)); cp5.addButton("temps") .setSize (380, 50) .setPosition(10, 500) .setColorBackground(color(70, 100, 0)) .setColorForeground(color(0, 0, 0)) .setFont(font) .setLabel("") .setImage(img6); } void settings(){ size(400, 560); } void draw() { background(fon); fill(0, 0, 0); textFont(font); text(" ", 135, 30); int s = second(); int m = minute(); int h = hour(); int d = day(); int mo = month(); int y = year(); DateTab = str(d)+ "." + str(mo) + "." + str(y) + (" ") + str(h) + (":") + str(m) + (":") + str(s); if ( port.available() > 0){ val = port.readString(); if(data2==0){ //        -   , recived.setText(val); // - com ,  -   . } /* data2 - ,    Second Applet     textfield   . */ } sa = new SecondApplet(); } void Relay_1(){ port.write("1"); } void Relay_2(){ port.write("2"); } void Relay_ON(){ port.write("3"); } void Relay_OFF(){ port.write("0"); } void Zapros_sostoyaniya(){ data2=0; port.write("4"); } void save123(){ //       data2=1; port.write("4"); delay(600); port.available(); Dat=DateTab + " " + val; table2 = loadTable("data/Journaltemp.ods"); //   table2.setString(0, 0, "t"); //     0.0 table2.removeColumn(0); /*  0,          */ TableRow newRow = table2.addRow(); //   newRow.setString(0, Dat); /*  0        ( )*/ saveTable(table2, "data/Journaltemp.ods"); //    data2=0; } void temps(){ PApplet.runSketch(args, sa); //  Second Applet } public class SecondApplet extends PApplet { public void setup(){ surface.setTitle(" "); surface.setIcon(titlebaricon); font2 = createFont("Arial", 20); /*   , ,    ..*/ ax = new ControlP5(this); ax.addButton("test1") .setSize(159, 70) .setPosition(1, 300) .setFont(font2) .setLabel(""); ax.addButton("test2") .setSize(158, 70) .setPosition(161, 300) .setFont(font2) .setLabel(""); ax.addButton("test3") .setSize(159, 70) .setPosition(320, 300) .setFont(font2) .setLabel(""); ax.addButton("test4") .setSize(159, 70) .setPosition(480, 300) .setFont(font2) .setLabel(""); ax.addButton("test5") .setSize(159, 70) .setPosition(640, 300) .setFont(font2) .setLabel(""); ax.addButton("obj") .setSize (790, 50) .setPosition(5, 540) .setColorBackground(color(70, 100, 0)) .setColorForeground(color(0, 0, 0)) .setFont(font) .setLabel(""); recived1 = ax.addTextfield(" ") .setSize(157, 70) .setPosition(2, 370) .setColorValueLabel(0) .setFont(font) .setColorBackground(color(255, 255, 255)); recived2=ax.addTextfield(" ") .setSize(156, 70) .setPosition(162, 370) .setColorValueLabel(0) .setFont(font) .setColorBackground(color(255, 255, 255)); recived3=ax.addTextfield(" ") .setSize(157, 70) .setPosition(321, 370) .setColorValueLabel(0) .setFont(font) .setColorBackground(color(255, 255, 255)); recived4=ax.addTextfield(" ") .setSize(157, 70) .setPosition(481, 370) .setColorValueLabel(0) .setFont(font) .setColorBackground(color(255, 255, 255)); recived5=ax.addTextfield(" ") .setSize(157, 70) .setPosition(641, 370) .setColorValueLabel(0) .setFont(font) .setColorBackground(color(255, 255, 255)); } public void settings() { size(800, 600); //    } public void draw() { background(fon2); //  )) textFont(font2); } public void test1(){ recived1.setText(" 11111"); } public void test2(){ recived2.setText(" 22222"); } public void test3(){ recived3.setText(" 33333"); //    Second Applet } public void test4(){ recived4.setText(" 44444"); } public void test5(){ recived5.setText(" 55555"); } public void obj(){ save123(); /*              */ } public void exitActual(){} //      [X]    . } //      ,       [X]. 


El programa que recib铆:

Tiempos
Dos

Te pido que no patees mucho: mi primer proyecto sobre Procesamiento, espero que alguien pueda resolverlo con cosas tan simples como resultaron. Y si alguien me dice c贸mo optimizar mi c贸digo g ..., me alegrar茅.

Source: https://habr.com/ru/post/478552/


All Articles