We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys! I need your help, as for now, I don't know why my processing code doesn't read the data from arduino as string. Here's my code. Arduino
int ledPin = 13;
int LDRpin = 0;
Servo myServo;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(LDRpin, INPUT);
Serial.begin(9600);
}
void loop()
{
int val = analogRead(LDRpin);
if(val > 30)
{
Serial.println("A");
digitalWrite(ledPin, HIGH);
delay(1000);
}else
if(val < 10)
{
Serial.println("B");
digitalWrite(ledPin, LOW);
delay(1000);
}
}
Processing
import processing.serial.*; Serial myPort; String inByte; void setup() { size(300,300); println(Serial.list()); myPort = new Serial(this, Serial.list()[0], 9600); myPort.bufferUntil('\n'); textSize(32); } void draw() { background(0); while(myPort.available() > 0){ inByte = myPort.readStringUntil('\n'); if(inByte != null) { println(inByte); if(inByte == "A") { println("ON"); }else { println("OFF"); } } } }
Here's the scenario: if my LDR's value is greater than 30, my LED turns ON and sends string data ("A") to processing, and when my processing receives a string data value "A", it will then output "ON", else "OFF". I think my processing doesn't read my arduino data as String? Please point this out to me :( Thank you in advance!
Answers
http://forum.processing.org/two/discussion/6689/how-to-compare-strings-sent-to-processing-by-arduino-board#Item_3
@Jellyfish: thanks for this sir, you gave me an Idea why this is happening. Cheers!