Processing 无法识别在处理过程中单击的鼠标

Processing 无法识别在处理过程中单击的鼠标,processing,mouseclick-event,arduino-uno,Processing,Mouseclick Event,Arduino Uno,我有8个简单的模拟土壤传感器连接到一个16通道模拟多路复用器,用于一个花园项目。传感器通过Arduino Uno读取。与Arduino相连的还有一个温度和光线传感器,每个传感器使用1个模拟引脚。我还在Arduino上运行Firmata,如果这有什么区别的话 过去只有4个传感器连接到Arduino上,但我必须扩展并加倍数量(因此使用多路复用器)。mouseClicked功能可以与4个传感器一起工作,但再增加4个传感器后就不再工作了。增加4个额外传感器是否会影响Arduino的内存(即过载),或者是

我有8个简单的模拟土壤传感器连接到一个16通道模拟多路复用器,用于一个花园项目。传感器通过Arduino Uno读取。与Arduino相连的还有一个温度和光线传感器,每个传感器使用1个模拟引脚。我还在Arduino上运行Firmata,如果这有什么区别的话

过去只有4个传感器连接到Arduino上,但我必须扩展并加倍数量(因此使用多路复用器)。mouseClicked功能可以与4个传感器一起工作,但再增加4个传感器后就不再工作了。增加4个额外传感器是否会影响Arduino的内存(即过载),或者是什么?我不确定问题出在哪里;任何帮助都将不胜感激

import processing.serial.*;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
import processing.video.*;
import cc.arduino.*;
Capture cam;
Arduino arduino;
Serial tinyg;
PImage bg;
PImage img; //green plant
PImage img2; //yellow sun
PImage img3; //brown plant
PImage img4; //gray sun
PImage img5; //plant petals
PFont font;
Serial port = null;
String portname = null;
boolean streaming = false;
float speed = 0.001;
String[] gcode;
int i = 0;
int lightReading=0;
int tempReading=0;
int toggle=0;
float voltage=0.0;
float tempc=0.0;
color off = color(4, 79, 111);
color on = color(84, 145, 158);
color brown = color(100, 59, 15);
color green = color(153, 204, 0, 0); //last number is alpha value for transparency
color black = color(000, 000, 000);
color transparentblack = color(000, 000, 000, 0);
float moisture_ref = 910.0; //change based on wet resistance value

int oldTime = 0;
int interval = 250;

int enable = 2;
int chan[][] = {
  {
    0, 0, 0, 0
  }
  , 
  {
    1, 0, 0, 0
  }
  , 
  {
    0, 1, 0, 0
  }
  , 
  {
    1, 1, 0, 0
  }
  , 
  {
    0, 0, 1, 0
  }
  , 
  {
    1, 0, 1, 0
  }
  , 
  {
    0, 1, 1, 0
  }
  , 
  {
    1, 1, 1, 0
  }
  , /*
  {
   0, 0, 0, 1
   }
   , 
   {
   1, 0, 0, 1
   }
   , 
   {
   0, 1, 0, 1
   }
   , 
   {
   1, 1, 0, 1
   }
   , 
   {
   0, 0, 1, 1
   }
   , 
   {
   1, 0, 1, 1
   }
   , 
   {
   0, 1, 1, 1
   }
   , 
   {
   1, 1, 1, 1
   } */
};

int sel[]= {
  3, 4, 5, 6
};

//array to hold soil values
int[] soilReading = new int[8];


void selectArduinoPort()
{
  if (port != null) port.stop();
  String result = (String) JOptionPane.showInputDialog(this, 
  "Select the serial port that corresponds to your Arduino board.", 
  "Select serial port", 
  JOptionPane.PLAIN_MESSAGE, 
  null, 
  Serial.list(), 
  0);

  if (result != null) {
    portname = result;
    arduino = new Arduino(this, portname, 57600);
  }
}

void selectTinygPort()
{
  if (port != null) port.stop();
  String result = (String) JOptionPane.showInputDialog(this, 
  "Select the serial port that corresponds to your TinyG board.", 
  "Select serial port", 
  JOptionPane.PLAIN_MESSAGE, 
  null, 
  Serial.list(), 
  0);

  if (result != null) {
    portname = result;
    tinyg = new Serial(this, portname, 115200);
  }
}

void setup() {
  size(800, 650);
  img = loadImage("plant5.png");
  img2 = loadImage("sun2.png");
  img3 = loadImage("plant8.png");
  img4 = loadImage("sun4.png");
  img5 = loadImage("plant9negative.png");

  String[] cameras = Capture.list();

  if (cameras == null) {
    println("Failed to retrieve the list of available cameras, will try the default...");
    cam = new Capture(this, 320, 240);
  } 
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } 
  else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }
    cam = new Capture(this, cameras[8]);
    cam.start();
  }
  println(Arduino.list());
  font=loadFont("Helvetica-24.vlw");
  textFont(font);
  selectArduinoPort();
  selectTinygPort();
  //openSerialPort();
}

void draw() {
  tint(255, 235);
  background(0);

  stroke(255);
  fill(0);
  rect(20, 50, 50, 50, 3, 3, 3, 3);
  rect(20, 120, 50, 50, 3, 3, 3, 3);
  rect(20, 190, 50, 50, 3, 3, 3, 3);
  rect(20, 260, 50, 50, 3, 3, 3, 3);

  stroke(255);
  fill(0);
  rect(265, 55, 330, 250, 6, 6, 6, 6); //frame around the video feed

    font = loadFont("Helvetica-24.vlw");
  textFont(font, 32);
  fill(255); //font color
  text("Collaborators", width/5-50, 35); //text and location
  text("Aaron", width/5-20, 85);
  text("Angelika", width/5-20, 155);
  text("Alex", width/5-20, 225);
  text("Brett", width/5-20, 295);

  for (int i = 1; i <= 4; i++) {
    image(img, width/5*i-75, height/2+5);
  } //this is the top row of plant icons

  for (int i = 1; i <= 4; i++) {
    image(img, width/5*i-75, height/2+165);
  } //this is the bottom row of plant icons

  if (cam.available() == true) {
    cam.read();
  }
  image(cam, width/2-130, height/2-265);
  stroke(off);
  ellipseMode(CENTER);

  //////
  for (int i=0; i<8; i++)
  {
    arduino.digitalWrite(enable, 1);
    for (int j=0; j<4; j++)
    {
      arduino.digitalWrite(sel[j], chan[i][j]);
    }
    arduino.digitalWrite(enable, 0);
    delay(25);
    soilReading[i]=arduino.analogRead(0);
  }

  if ((millis()-oldTime)>interval)
  {
    //top row
    for (int i = 1; i <= 4; i++) {
      //print("sensor"+1+": "+arduino.analogRead(1)+" ");
      //println("");
      color col=lerpColor(brown, green, soilReading[i-1]/moisture_ref);//reads analog A0, interpolates color
      fill(col);
      stroke(col);
      ellipse(width/5*i-15, height/2+65, 120, 120); //width/5*i, height/2+300, 175, 175
      font = loadFont("Helvetica-24.vlw");
      textFont(font, 32);
      textAlign(CENTER);
      fill(255); //previously 0
      text(ceil(soilReading[i-1]/1024.0*100)+"%", width/5*i-10, height/2+154); //values below top row of plant icons
      //delay(50);
    }
    //bottom row
    for (int i = 1; i <= 4; i++) {
      //print("sensor"+1+": "+arduino.analogRead(1)+" ");
      //println("");
      color col=lerpColor(brown, green, soilReading[i*2-1]/moisture_ref);//reads analog A0, interpolates color
      fill(col);
      stroke(col);
      ellipse(width/5*i-15, height/2+225, 120, 120); //width/5*i, height/2+300, 175, 175
      font = loadFont("Helvetica-24.vlw");
      textFont(font, 32);
      textAlign(CENTER);
      fill(255); //previously 0
      text(ceil(soilReading[i*2-1]/1024.0*100)+"%", width/5*i-10, height/2+315); //values below bottom row of plant icons
      //delay(50);
    }
    oldTime = millis();
  }

  delay(50);
  //////


  for (int i = 1; i <= 4; i++) {
    image(img5, width/5*i-75, height/2+5);
  } //this is the overlay for the top row of plant icons

  for (int i = 1; i <= 4; i++) {
    image(img5, width/5*i-75, height/2+165);
  } //this is the overlay for the bottom row of plant icons


  //read the light sensor on pin A5
  lightReading=arduino.analogRead(5);
  delay(10);
  lightReading=arduino.analogRead(5);
  print("light: "+lightReading);
  delay(10);

  //read the temp sensor on pin A1
  tempReading=arduino.analogRead(1);
  delay(10);
  tempReading=arduino.analogRead(1);
  delay(10);

  //convert temp reading to degrees centigrade  
  voltage=tempReading*(5000/1024.0);
  tempc=ceil((voltage-500)/10.0);
  println(" temp: "+tempc);
  text(tempc+"\u00B0C", width/2+295, 270);

  image(img2, width/2+220, 80, 150, 150);

  // sun
  color col2=lerpColor(black, transparentblack, lightReading/900.0);//reads analog A05, interpolates color
  fill(col2);
  stroke(col2);
  ellipse(width/2+295, 155, 150, 150); //width/5*i, height/2+300, 175, 175
  fill(255); //previously 0
}

//manual motion

//this set is for the top row
void mouseClicked() {
  if (mouseY>80 && mouseY<200 && mouseX>325 && mouseX<445 && toggle==0) {
    tinyg.write("G91G1X250F5000\n");
    tinyg.write("G91G1Y70F5000\n");
    toggle=1;
    return;
  }
  if (mouseY>80 && mouseY<200 && mouseX>325 && mouseX<445 && toggle==1) {
    tinyg.write("G91G1X0F5000\n");
    tinyg.write("G91G1Y0F5000\n");
    toggle=0;
    return;
  }
  if (mouseY>240 && mouseY<390 && mouseX>325 && mouseX<445 && toggle==0) {
    tinyg.write("G91G1X250F5000\n");
    tinyg.write("G91G1Y275F5000\n");
    toggle=1;
    return;
  }
  if (mouseY>240 && mouseY<390 && mouseX>325 && mouseX<445 && toggle==1) {
    tinyg.write("G91G1X0F5000\n");
    tinyg.write("G91G1Y0F5000\n");
    toggle=0;
    return;
  }
  if (mouseY>405 && mouseY<555 && mouseX>325 && mouseX<445 && toggle==0) {
    tinyg.write("G91G1X250F5000\n");
    tinyg.write("G91G1Y500F5000\n");
    toggle=1;
    return;
  }
  if (mouseY>405 && mouseY<555 && mouseX>325 && mouseX<445 && toggle==1) {
    tinyg.write("G91G1X0F5000\n");
    tinyg.write("G91G1Y0F5000\n");
    toggle=0;
    return;
  }
  if (mouseY>570 && mouseY<720 && mouseX>325 && mouseX<445 && toggle==0) {
    tinyg.write("G91G1X250F5000\n");
    tinyg.write("G91G1Y725F5000\n");
    toggle=1;
    return;
  }
  if (mouseY>570 && mouseY<720 && mouseX>325 && mouseX<445 && toggle==1) {
    tinyg.write("G91G1X0F5000\n");
    tinyg.write("G91G1Y0F5000\n");
    toggle=0;
    return;
  }

  //this set is for the bottom row
  if (mouseY>80 && mouseY<200 && mouseX>485 && mouseX<605 && toggle==0) {
    tinyg.write("G91G1X350F5000\n");
    tinyg.write("G91G1Y70F5000\n");
    toggle=1;
    return;
  }
  if (mouseY>80 && mouseY<200 && mouseX>485 && mouseX<605 && toggle==1) {
    tinyg.write("G91G1X0F5000\n");
    tinyg.write("G91G1Y0F5000\n");
    toggle=0;
    return;
  }
  if (mouseY>240 && mouseY<390 && mouseX>485 && mouseX<605 && toggle==0) {
    tinyg.write("G91G1X350F5000\n");
    tinyg.write("G91G1Y275F5000\n");
    toggle=1;
    return;
  }
  if (mouseY>240 && mouseY<390 && mouseX>485 && mouseX<605 && toggle==1) {
    tinyg.write("G91G1X0F5000\n");
    tinyg.write("G91G1Y0F5000\n");
    toggle=0;
    return;
  }
  if (mouseY>405 && mouseY<555 && mouseX>485 && mouseX<605 && toggle==0) {
    tinyg.write("G91G1X350F5000\n");
    tinyg.write("G91G1Y500F5000\n");
    toggle=1;
    return;
  }
  if (mouseY>405 && mouseY<555 && mouseX>485 && mouseX<605 && toggle==1) {
    tinyg.write("G91G1X0F5000\n");
    tinyg.write("G91G1Y0F5000\n");
    toggle=0;
    return;
  }
  if (mouseY>570 && mouseY<720 && mouseX>485 && mouseX<605 && toggle==0) {
    tinyg.write("G91G1X350F5000\n");
    tinyg.write("G91G1Y725F5000\n");
    toggle=1;
    return;
  }
  if (mouseY>570 && mouseY<720 && mouseX>485 && mouseX<605 && toggle==1) {
    tinyg.write("G91G1X0F5000\n");
    tinyg.write("G91G1Y0F5000\n");
    toggle=0;
    return;
  }
}

//turn water pump on/off

void keyPressed() {
  arduino.digitalWrite(2, Arduino.HIGH);
}

void keyReleased() {
  arduino.digitalWrite(2, Arduino.LOW);
}
import processing.serial.*;
导入java.awt.event.KeyEvent;
导入javax.swing.JOptionPane;
导入处理。视频。*;
进口cc.arduino。*;
捕捉凸轮;
阿尔杜伊诺;
序列tinyg;
皮马杰bg;
皮马杰//绿色植物
PImage-img2//黄日
PImage img3//棕色植物
PImage img4//灰色的太阳
PImage img5//植物花瓣
字体;
串口=空;
字符串portname=null;
布尔流=假;
浮动速度=0.001;
字符串[]gcode;
int i=0;
int lightReading=0;
int-tempReading=0;
int-toggle=0;
浮动电压=0.0;
浮动温度c=0.0;
色差=颜色(4,79,111);
颜色开=颜色(84145158);
颜色棕色=颜色(100,59,15);
绿色=颜色(153,204,0,0)//最后一个数字是透明度的alpha值
颜色黑色=颜色(000000000);
颜色透明度黑色=颜色(000000000,0);
浮子水分_ref=910.0//根据湿阻值进行更改
int oldTime=0;
整数区间=250;
int enable=2;
int chan[][]={
{
0, 0, 0, 0
}
, 
{
1, 0, 0, 0
}
, 
{
0, 1, 0, 0
}
, 
{
1, 1, 0, 0
}
, 
{
0, 0, 1, 0
}
, 
{
1, 0, 1, 0
}
, 
{
0, 1, 1, 0
}
, 
{
1, 1, 1, 0
}
, /*
{
0, 0, 0, 1
}
, 
{
1, 0, 0, 1
}
, 
{
0, 1, 0, 1
}
, 
{
1, 1, 0, 1
}
, 
{
0, 0, 1, 1
}
, 
{
1, 0, 1, 1
}
, 
{
0, 1, 1, 1
}
, 
{
1, 1, 1, 1
} */
};
int sel[]={
3, 4, 5, 6
};
//用于保存土壤值的数组
int[]soilReading=新int[8];
void selectArduInPort()
{
如果(port!=null)port.stop();
字符串结果=(字符串)JOptionPane.showInputDialog(此,
“选择与Arduino板对应的串行端口。”,
“选择串行端口”,
JOptionPane.PLAIN\u消息,
无效的
Serial.list(),
0);
如果(结果!=null){
portname=结果;
arduino=新的arduino(此端口名为57600);
}
}
void selectTinygPort()
{
如果(port!=null)port.stop();
字符串结果=(字符串)JOptionPane.showInputDialog(此,
“选择与TinyG板对应的串行端口。”,
“选择串行端口”,
JOptionPane.PLAIN\u消息,
无效的
Serial.list(),
0);
如果(结果!=null){
portname=结果;
tinyg=新序列号(此端口号为115200);
}
}
无效设置(){
尺寸(800650);
img=loadImage(“plant5.png”);
img2=loadImage(“sun2.png”);
img3=加载图像(“plant8.png”);
img4=loadImage(“sun4.png”);
img5=loadImage(“plant9negative.png”);
String[]cameras=Capture.list();
如果(摄像机==null){
println(“检索可用摄像头列表失败,将尝试默认…”);
cam=新捕获(此,320,240);
} 
if(cameras.length==0){
println(“没有可供拍摄的摄像机”);
退出();
} 
否则{
println(“可用摄像机:”);
对于(int i=0;i对于(inti=1;i),当你说它不起作用时,你到底是什么意思?你能更具体一点吗?你能把你的问题缩小到一个小范围吗?