Bir projemde arduino ve processing kullanarak step motoru kontrol etmek istiyorum. Bunun için basit bir arayüz tasarladım. Arayüzdeki textboxa girilen adım değeri kadar motoru çevirmek istiyorum ancak program sürekli hata veriyor. Sorun ne olabilir, nasıl düzeltebilirim?
Processing kodu
import controlP5.*;
import processing.serial.*;
Serial myPort;
boolean bas=false;
boolean acibas=true;
int rectX, rectY; // Position of square button
int rectSize = 120; // Diameter of rect
color rectColor, baseColor;
color rectHighlight;
color currentColor;
boolean rectOver = false;
boolean rectOver2 = false;
int yon=0;
ControlP5 cp5;
void setup() {
size(600, 550);
rectColor = color(0);
rectX = 350;
rectY = 80;
rect(rectX, rectY, rectSize, rectSize);
rect(130, 80, rectSize, rectSize);
cp5 = new ControlP5(this);
textSize(32);
cp5.addTextfield("ANGLE").setPosition(75, 300).setSize(200, 80).setFont(createFont("arial",32)).setAutoClear(false);
text("C-CW", 130, 60);
text("CW", 350, 60);
cp5.addBang("SUBMIT").setPosition(325, 300).setFont(createFont("arial",32)).setSize(160, 80);
myPort = new Serial(this, "COM3", 9600);
myPort.bufferUntil('\n');
}
void draw() {
int adim;
String Sadim = cp5.get(Textfield.class,"ANGLE").getText();
adim = Integer.parseInt(Sadim);
update(mouseX, mouseY);
if(bas){
if(yon==1){
myPort.write("b");
}
if(yon==2){
myPort.write("a");
}
bas=false;
}
}
void controlEvent(ControlEvent deger) {
if(deger.isAssignableFrom(Textfield.class)) {
println("controlEvent: accessing a string from controller '"+deger.getName()+"': "
+deger.getStringValue()
);
}
}
void update(int x, int y) {
if ( overRect(rectX, rectY, rectSize, rectSize) ) {
rectOver = true;
rectOver2 = false;
} else if( overRect(130, 80, rectSize, rectSize) ){
rectOver2 = true;
rectOver = false;
} else {
rectOver = rectOver2 = false;
}
}
void mousePressed() {
bas=true;
if (rectOver) {
yon=2;
}else if (rectOver2) {
yon=1;
}
else{
yon=0;
}
}
boolean overRect(int x, int y, int width, int height) {
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}