hi guys, i’m trying to make a school project with arduino and processing but I have a problem.
I’m trying to make a controller with 4 buttons that send the digital signal via serial to a processing game that I made, i succeded into sending the data but the problem is that i can’t undestand why the player is not moving.
here attached the two codes, hope you can find out what is the problem and thank you very much!!!
here is the processing code
import processing.serial.*;
Serial myPort;
String valori;
    
int  score=0;
float n=3, b=-3, p, o, c=0, v=0, x=200, y=200;
void setup() {
  
myPort = new Serial(this, "COM3",9600);
 size (800,800); 
 p=random(800);
 o=random(800);
}
void draw () {
  
  
 background (200,140,70);                      //punto rosso
 fill (255,40,40);
 rect(p,o,5,5);
 
 
 fill(random(255),random(255),random(255));    //giocatore
 rect (x,y,20,20);
 x=x+c;
 y=y+v; 
if (x>=p-25 && x<=p+5 && y>=o-25 && y<=o+5)  //se la palla colpisce il punto rosso il punto si sposta il punteggio aumenta di uno e la velocità aumenta
{
  o=random(800);
  p=random(800);
  score++;
n=n+0.15;
b=b-0.15;
}
 if (y>800) {y=y-800;}                  //se la palla va fuori esce dalla parte opposta della finestra
 if (x>800) {x=x-800;}
 if (y<0) {y=y+800;}
 if (x<0) {x=x+800;}
   if (myPort.available()>0) {
   valori = myPort.readStringUntil('\n');  
 }
 
if(valori != null){
if (valori=="1");{c=b; v=0;}
if (valori=="2");{c=n; v=0;}
if (valori=="3");{v=b; c=0;}
if (valori=="4");{v=n; c=0;}
}
println(valori);
if(valori!=null){
fill(255);                             // punteggio
text (valori,400,750);
textSize(35);
}
}
and here the arduino one
int val, val1, val2,val3;
int x;
void setup() {
pinMode(8,INPUT);
pinMode(9,INPUT);
pinMode(10,INPUT);
pinMode(11,INPUT);
Serial.begin(9600);
}
void loop() {
val=digitalRead(8);
val1=digitalRead(9);
val2=digitalRead(10);
val3=digitalRead(11);
if (val==HIGH) {
  x=1;
}
if (val1==HIGH) {
  x=2;
}
if (val2==HIGH) {
  x=3;
}
if (val3==HIGH) {
  x=4;
}
Serial.println(x);
delay(80);
}