Bonjour a tous,
Je continue ma découverte de l'Arduino et du code et je test Processing.
Je commence les tuto du site officiel et ça ne marche pas.
Le but est de lire l’état d'un switch et changer la couleur d'un rectangle en fonction.
code arduino :
const byte switchPinTurnLeft=4;
boolean switchValueTurnLeft=HIGH;
void setup(){
Serial.begin(9600);
pinMode(switchPinTurnLeft, INPUT_PULLUP);
}
void loop(){
switchValueTurnLeft=(digitalRead(switchPinTurnLeft)==LOW);
if (switchValueTurnLeft==HIGH){
Serial.write(1);
Serial.print("YES");
}
else {
Serial.write(0);
Serial.print("NO");
}
delay(100);
}
Code Processing :
import processing.serial.*;
Serial port;
int val;
void setup() {
size(200, 200);
frameRate(10);
port = new Serial(this, 9600);
}
void draw() {
if (0 < port.available()) {
val = port.read();
}
background(255);
if (val == 0) {
fill(0);
} else {
fill(204);
}
rect(50, 50, 100, 100);
}
Sur le serial.print Arduino j'ai bien l état du switch qui change, du coté Processing j ai le rectangle avec la première couleur mais elle ne change pas.
Auriez vous une idée ?
Pour info j utilise processing 1.5.1
MERCI