this is my first question so i try my best to explain it good enough. My Goal is to gather a number via processing from my website and send it to my arduino. I try to turn my led on when the number 1 comes in or turn it off when the number 0 comes in.
So far i managed to gather the number from my website. And when i send a number with the arduino serial monitor to the arduino the arduino code works, too.
The part that is not working is the sending of the number from processing to the arduino. The led just flickers once.
Here is my processing code:
import processing.serial.*;
Serial ComPort;
String input[];
void setup(){
String portName = Serial.list() [0];
ComPort = new Serial(this, portName, 9600);
ComPort.bufferUntil('\n');
input = loadStrings("website-adresse");
if(input.length != 0){
String s_current = input[0];
int current = Integer.parseInt(s_current);
println(current);
delay(2000);
ComPort.write(current);
}
}
Here is my arduino code:
void setup() {
Serial.begin(9600); // Baudrate, muss mit PC übereinstimmen
pinMode(13,OUTPUT);
}
void loop() {
int c = Serial.read();
switch (c) {
case -1: return; // nichts neues gekommen, loop sofort beenden
case '0' :
digitalWrite(13, LOW);
break;
case '1' :
digitalWrite(13, HIGH);
break;
}
}
Iam new to programming and my english is not that good so i apologize for that.
Thanks for your help
Greetings Jenni