HI, I’m new in Processing, and i want to use arduino and make rotary encoder as arrows. Unfortunetly i have only Uno, not leonardo, so i wanted to made a code in processing to emulate pressing a key. But evry time i want to run, i have error
Blockquote Error, disabling serialEvent() for COM6 null.
My code :
import processing.serial.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
Serial MyPort;
String KeyString = “”;
void setup()
{
System.out.println(“Hi”);
size(300, 300);
MyPort = new Serial(this, “COM6”, 9600);// My Arduino is on COM3. Enter the COM on which your Arduino is on.
MyPort.bufferUntil(‘\n’);
}
void draw(){
background(237, 240, 241);
fill(20, 160, 133); // Green Color
stroke(33);
strokeWeight(1);
textSize(32);
textSize(24);
fill(33);
text(“Status:”, 100, 150);
textSize(30);
textSize(16);
text(“Joystick”, 100, 50);
text(KeyString, 100, 170);
}
void serialEvent(Serial MyPort)throws Exception {
KeyString = MyPort.readStringUntil(‘\n’);
KeyString = KeyString.substring(0, KeyString.indexOf(‘:’));
System.out.println(KeyString);
Robot Arduino = new Robot();
int KeyToPress;
switch(KeyString){
case “1” :
Arduino.keyPress(38);
Arduino.keyRelease(38);
break;
case “2” :
Arduino.keyPress(39);
Arduino.keyRelease(39);
break;
case “3” :
Arduino.keyPress(40);
Arduino.keyRelease(40);
break;
case “4” :
Arduino.keyPress(37);
Arduino.keyRelease(37);
break;
}
}
Help please!