Newbie MouseClicked() Serial Write
in
Core Library Questions
•
1 year ago
I'm trying to use processing to create a simple graphical front end to operate a stepper motor that I have hooked up to an Arduino. Currently, I have a program on the arduino such that it is listening for serial communication to move the stepper motor. I have two "buttons" that I've created with processing. The goal being that when I click on the upper button, it writes a value to the serial buffer, and when I click the lower button, it sends a different value. Here is my current code:
import processing.serial.*;
void setup(){
Serial myPort;
myPort= new Serial(this, Serial.list()[1], 9600);
myPort= new Serial(this, Serial.list()[1], 9600);
size(320,400);
}
}
void draw(){
background(0);
fill(128);
rect(100,100,50,50);
rect(100,200,50,50);
}
background(0);
fill(128);
rect(100,100,50,50);
rect(100,200,50,50);
}
void mouseClicked(){
if(mouseX > 100 && mouseX < 150 && mouseY > 100 && mouseY < 150){
println("up");
myPort.write(56);
}
if(mouseX > 100 && mouseX < 150 && mouseY > 200 && mouseY < 250){
println("down");
myPort.write(50);
}
}
println("up");
myPort.write(56);
}
if(mouseX > 100 && mouseX < 150 && mouseY > 200 && mouseY < 250){
println("down");
myPort.write(50);
}
}
I get the message "Cannot find anything named "myPort".
I'm very new to processing, and any information would be very helpful.
Thanks!
1