Good day,
Im a bit of a novice and for a school project we are required to make a servo move using Processing and using port.write('value'); to send data from processing to arduino ide.
Would anyone be able to share some insight into what is wrong with my code ?
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
Servo myservo;
char val;
void setup() {
Serial.begin(9600);
myservo.attach(9);
}
void loop() {
if (Serial.available()) {
// read the incoming byte:
val = Serial.read();
}
if (val == '1') { // 1 = value that is comming from processing
myservo.write(100);
delay(1000);
}
else if (val == '2' ){
myservo.detach()
}
}
My processing code is simple,
void mousePressed() {
if(mouseX > 500){
port.write('1');
print("yes");
}
else if (mouseX < 500){
port.write('2');
print("no");
}
}
Just sending a 1 or 2 when the mouse is pressed at a certain position on the Canvas. My port assignment and Com is all correct i just dont understand why Arduino is not reading the incoming bytes.
Thanks for your help !