第二个小程序,在处理3中将其关闭和透明按钮

给所有KU。 我的第一篇文章,请不要严格判断。

需要进行工作以可视方式读取设备的状态,并在必要时远程重新启动冷冻压缩机。 随手买了Arduino UNO,为此购买了一个环境光传感器,到目前为止,有2个继电器和2个12 V的螺线管(不是重点)。 将来,该行业将充满温度,湿度和压力传感器,但到目前为止尚未完成。

撰写该帖子的原因是,互联网上关于处理3功能的信息很少,尤其是其中俄语部分。 我希望有一天像我这样的茶壶能派上用场,以免在过去一周里像我这样愚蠢。

Arduino的草图很简单,只有三个卢布:从com端口接收到某些值后,扣篮将值设置在引脚上,并将答案写入com端口,还测量照度并报告。 将来,它将被扩展。

素描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  !!!!!!!"); } } } } 

我认为这毫无疑问,但是由于其他人将来会使用我的Pribluda的功能,我想编写一个简单但易于理解的GUI。 之所以选择使用Processing,是因为我以前很熟悉Arduino IDE,而Arduino IDE是在Processing的基础上构建的。

小程序使用ControlP5库来呈现控件。

就个人而言,我在实现和搜索有关以下内容的信息时遇到问题:1)从应用程序启动第二个窗口,2)关闭第二个窗口,但以便主窗口继续工作,3)为了好玩-将图片设置为背景,按钮,半透明按钮。

因此,处理草图:

代码清单
 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]. 


我收到的程序:

时报
两个

我要求您不要花太多时间-我的第一个有关Processing的项目,希望有人可以用事实证明的简单方法来解决。 如果有人告诉我如何优化我的g ...代码-我会很高兴。

Source: https://habr.com/ru/post/zh-CN478552/


All Articles