We are about to switch to a new forum software. Until then we have removed the registration on this forum.
What I am trying to do is read some IR signals.
The code in Arduino is:
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value);
irrecv.resume(); // Receive the next value
}
delay(100);
}
It reads the IR signals, and suppose, Now I want to get this at Processing and want to open a webpage for that.
// Example by Tom Igoe
import processing.serial.*;
Serial myPort; // The serial port
String inString; // Input string from serial port
int lf = 10; // ASCII linefeed
void setup() {
size(400,200);
// List all the available serial ports:
println(Serial.list());
// Open the port you are using at the rate you want:hat
myPort = new Serial(this, "COM9", 9600);
myPort.bufferUntil(lf);
}
void draw() {
background(0);
text("received: " + inString, 10,50);
}
void serialEvent(Serial p) {
inString = p.readString();
if(inString.equals("544993039")){
String[] params = { "start www.google.com" };
open(params);
}
}
`
But however even though the signal of that value is caught in the receiver, but the codes do not get executed! :/
I am 100% sure that the signal reaches the receiver as Arduino seems to do what I want it to do when I send signals, for example when I use this code:
if(results.value == 544993039) { digitalWrite(8, HIGH); }
Anything connected to pin 8 seems to work just fine.
but in Processing:
if(inString.equals("544993039")){
String[] params = { "start www.google.com" };
open(params);
}
Nothing seems to happen. Can anybody help me please?
Answers
You'll get a better response if you format your code:
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
Try putting a
println(inString);
after the p.readString() to make sure that you're receiving the right thing.Really sorry for the formatting, I am totally new in here. Took me a few minutes to figure out how to format.
And I am certain that the value match. Because when I use this code in Arduino:
if(results.value == 544993039) { digitalWrite(8, HIGH); }
anything connected to pin 8 seems to work, but Processing doesn't seem to do anything.
Maybe inString needs some trim()? :-??
WoW! It's working! _ Man! I fucking Love You! :D :D THank you soo MUCH! ^_^
A couple more things to try:
Insert
inString = inString.trim()
between lines 40 and 41 to make sure that a linefeed on the end of the string isn't messing up the comparison.Substitute
if (true) {
for line 42 to see if the action you expect really does something. (It of course doesn't do anything on my Mac.)Edit: GoToLoop slipped in while my back was turned. Well done!