這是我在處理過程中寫的一段代碼。簡單寫入處理
{ import processing.serial.*;
Serial myPort;
// Create object from Serial class int val;
// Data received from the serial port
void setup() { size(860, 860);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using. String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
}
void draw() {
background(255);
if ((mouseX >100)&&(mouseY>50)&&(mousePressed))
{
// If mouse is over square, fill(204);
// change color and myPort.write('U');
// send an H to indicate mouse is over square println("U"); } rect(100, 50, 100, 100); // UP if ((mousePressed)&&(mouseX>50)&&(mouseY>200)) { // If mouse is over square, fill(204);
// change color and myPort.write('L'); // send an H to indicate mouse is over square println("L"); } rect(50, 200, 100, 100);//LEFT
if ((mousePressed)&&(mouseX>180)&&(mouseY>200)){ // If mouse is over square, fill(204);
// change color and myPort.write('R');
// send an H to indicate mouse is over square println("R");
}
rect(180, 200, 100, 100);
//RIGHT
if ((mousePressed)&&(mouseX>100)&&(mouseY>350)) { // If mouse is over square, fill(204);
// change color and myPort.write('B');
// send an H to indicate mouse is over square println("B");
}
rect(100, 350, 100, 100);//BACK
}
}
我想發送的輸出U,L,R,跨串行端口B每當鼠標懸停是在任何的4盒等。頂盒U,底盒D,左盒L等。但我得到的是ULD而不是D,LUL而不是L和其他各種雜亂無章的輸出。請幫忙。並且請忽略我的代碼中的評論。謝謝
請以有組織和易讀的方式呈現您的代碼 –
如何?對不起,我剛加入SO。 – Mahip
您的代碼難以辨認。請重新格式化並從左側4個空格處開始縮進,以便在此處正確顯示。 – ThisClark