- Need another new libraries.
- This is the code for java.
- My porposes are sending from java to arduino variable like this
String = "hello"But nothing Its happiens.
Java code:
package j;
import arduino.*;
public class K {
public static void main(String[] args) {
Arduino obj = new Arduino("COM4", 115200);
obj.openConnection();
String MyStr="hello";
System.out.println(MyStr);
obj.serialWrite(MyStr);
obj.closeConnection();
}
}
This is minimal arduino code fragment: It's working if from console send "hello" ,"1","2", "help" String vars.
Arduino code:
int RR=255;
int GG=255;
int BB=255;
String MyStr="0";
void setup() {
Serial.begin(115200);
Serial.setTimeout(0);
}
void loop() {
//L0();
while (Serial.available()>0) { //if data has been written to the Serial stream
//data0=Serial.read();
String MyStr = Serial.readString();
if ((MyStr).equals("1")){
Serial.println (MyStr);
RR=200;GG=0;BB=0;
}
if (MyStr == ("2")) {
Serial.println (MyStr);
RR=0;GG=0;BB=255;
}
if (MyStr == "hello") {
Serial.println (MyStr);
RR=0;GG=244;BB=0;
}
if (MyStr == "help") {
Serial.println (MyStr);
RR=225;GG=255;BB=255;
}
}
}
lang-java
if ("1".equals(data0))is what you need. Duplicate