Serial to Arduino Problem, please help!
in
Integration and Hardware
•
2 years ago
This has been killing me, so I would really appreciate help on this. I'm trying to send the X and Y axis plot from Processing to an Arduino, each having 3 digits. Bellow you can see the code for the Arduino, I'm simply trying to run a test to see if the Processing is sending X: 123, hence the IF statement.
Thank you for anything!
- int incoming;
int A;
int B;
int C;
int D;
int E;
int F;
int X;
int Y;
int ledPin = 13;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
Serial.println("start");
}
void loop()
{
// uint8_t c;
if(Serial.available() > 0)
{
delay(2000);
incoming = (Serial.read()-48);
A = incoming;
if(Serial.available()>0)
{
incoming = (Serial.read()-48);
B = incoming;
}
if(Serial.available()>0)
{
incoming = (Serial.read()-48);
C = incoming;
}
if(Serial.available()>0)
{
incoming = (Serial.read()-48);
D = incoming;
}
if(Serial.available()>0)
{
incoming = (Serial.read()-48);
E = incoming;
}
if(Serial.available() > 0);
{
incoming = (Serial.read()-48);
F = incoming;
}
X = ((A*100)+(B*10)+C);
Y = ((D*100)+(E*10)+F);
Serial.print("X: ");
Serial.print(X);
Serial.print(" Y: ");
Serial.println(Y);
if(X == 123)
{
digitalWrite(ledPin, HIGH);
}
if(X != 123)
{
digitalWrite(ledPin, LOW);
}
}
}
- import processing.serial.*;
Serial myPort;
int A = 123456;
void setup()
{
myPort = new Serial(this, Serial.list()[1], 9600);
}
void draw()
{
if(mousePressed)
{
myPort.write(123456);
//myPort.write(A);
//myPort.write(int(A));
//myPort.write(binary(A));
}
if(myPort.available() > 0)
{
delay(50);
// print(myPort.read()-48);
print(" ");
println(myPort.read()-48);
}
}
Thank you for anything!
1