Error, disabling serialEvent() for //./COM5
in
Core Library Questions
•
1 year ago
Hello!
I'm new to programming with processing. I was searching the internet and found
this game for processing. I liked it and decided to make a controler for it with Arduino. I've changed the game code but this error occurs when I try to run it:
- error, disabling serialEvent() for //./COM5
- java.lang.reflect.InvocationTargetException
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at processing.serial.Serial.serialEvent(Unknown Source)
- at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
- at gnu.io.RXTXPort.eventLoop(Native Method)
- at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
- Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
- at ardgame.serialEvent(ardgame.java:74)
- ... 8 more
This is my code for Processing:
- import processing.serial.*;
- int sphD = 10;
- boolean shoot = false;
- Serial myPort;
- String inString;
- float x = 0;
- int butt = 0;
- int buttPS = 0;
- int buttCS = 0;
- int randx()
- {
- return int(random(600));
- }
- int[] sphXcord = { randx(), randx(), randx(), randx(), randx() };
- int[] sphYcord = { 0, 0, 0, 0, 0 };
- void setup()
- {
- size(600, 620);
- println(Serial.list());
- myPort = new Serial(this, Serial.list()[1], 9600);
- myPort.buffer(3);
- }
- void draw()
- {
- background(0);
- fill(color(0, 255, 0));
- stroke(color(0, 255, 0));
- triangle(x-8, 580, x+8, 580, x, 565);
- fill(color(255,0,0));
- stroke(color(255,0,0));
- if(shoot==true)
- {
- sphereKiller(int(x));
- shoot = false;
- }
- sphereDropper();
- gameEnder();
- delay(25);
- }
- void serialEvent(Serial myPort)
- {
- inString = myPort.readStringUntil('\n');
- if(inString != null)
- {
- inString = trim(inString);
- int sensors[] = int(split(inString, ','));
- println("Sensor1: " + sensors[0] + "\tSensor2: " + sensors[1]);
- float val = float(sensors[0]);
- x = map(val, 0, 1023, 0, 600);
- buttCS = int(sensors[1]);
- if(int(sensors[1]) == 1)
- {
- if(buttCS != buttPS)
- {
- buttPressed();
- buttPS = buttCS;
- }
- }
- else
- {
- buttPS = 0;
- }
- }
- }
- void buttPressed()
- {
- shoot = true;
- }
- void sphereDropper()
- {
- stroke(255);
- fill(255);
- for(int i = 0; i < 5; i++)
- {
- ellipse(sphXcord[i], sphYcord[i]++, sphD, sphD);
- }
- }
- void sphereKiller(int shotX)
- {
- boolean hit = false;
- for (int i = 0; i < 5; i++)
- {
- if((shotX >= (sphXcord[i]-sphD/2)) &&
- (shotX <= (sphXcord[i]+sphD/2)))
- {
- hit = true;
- line(shotX, 565, shotX, sphYcord[i]);
- ellipse(sphXcord[i], sphYcord[i],
- sphD+25, sphD+25);
- sphXcord[i] = randx();
- sphYcord[i] = 0;
- }
- }
- if(hit == false)
- {
- line(shotX, 565, shotX, 0);
- }
- }
- void gameEnder()
- {
- for (int i=0; i< 5; i++)
- {
- if(sphYcord[i]==600)
- {
- fill(color(255,0,0));
- noLoop();
- }
- }
- }
- int val;
- void setup()
- {
- pinMode(2, INPUT);
- Serial.begin(9600);
- delay(1000);
- }
- void loop()
- {
- val = analogRead(A0);
- Serial.print(val);
- delay(2);
- Serial.print(",");
- val = digitalRead(2);
- Serial.println(val);
- delay(2);
- }
Sorry for my English
Thanks in advance
1