Hi all,
I'm trying to send data from Processing to Arduino but something is wrong. When I initialize "Serial.begin(9600)" in Arduino, it starts printing 1's. The data will eventually come into Arduino but it is conflicting with the never ending stream of 1's.
Arduino Code:
void setup() {
for (int i = 1; i < 9; i++) {
pinMode(i, OUTPUT);
}
Serial.begin(9600);
}
void loop() {
int input = Serial.read();
if (input == 1) {
digitalWrite(1,HIGH);
} else {
digitalWrite(2,LOW);
digitalWrite(3,LOW);
}
if (input == 2) {
digitalWrite(2,HIGH);
} else {
digitalWrite(1,LOW);
digitalWrite(3,LOW);
}
if (input == 3) {
digitalWrite(3,HIGH);
} else {
digitalWrite(2,LOW);
digitalWrite(1,LOW);
}
}
Processing code:
import processing.serial.*;
Serial myPort;
void setup() {
size(600, 300);
myPort = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
myPort.write(1);
}
Thx