We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Anyone knows how to send a message from arduino to processing? I'm a newbee here and I'm currently doing my experiment wherein I have an LDR and LED, if the LDR sensed light, the LED will turn ON, else OFF, and at the same time the arduino sends data like "the LED is turned ON" to processing, then the processing will output the message sent from the arduino. I have my code here, but it doesn't work as I wanted to.
Processing import processing.serial.*; Serial myPort; int inByte;
void setup()
{
size(300,300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
textSize(32);
}
void draw()
{
background(0);
while(myPort.available() > 0){
inByte = myPort.read();
println(inByte);
if(inByte > 30)
{
text("The LED is turned ON",width/2,height/2);
}else
{
text("The LED is turned OFF",width/2,height/2);
}
}
}
arduino
int ledPin = 13;
int LDRpin = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(LDRpin, INPUT);
Serial.begin(9600);
}
void loop()
{
int val = analogRead(LDRpin);
if(val > 30)
{
digitalWrite(ledPin, HIGH);
delay(1000);
Serial.println(val);
Serial.println("Led is on!");
}else
{
digitalWrite(ledPin, LOW);
Serial.println("Led is off");
delay(1000);
Serial.println(val);
}
}
I need some of your ideas guys :D Anyway, I'm still searching for answers at google :3 Just wondering if someone here can point it out to me :D Thanks in advance!
Answers
Moved to arduino category.
Upon searching from google, I got the answer XD Don't mind this thread anymore. LOL