I am reasonably new to arduino and even newer to Processing so still struggle with trouble shooting my code.
The intention of my sketch is have Processing receive IR codes from the arduino and execute different AppleScript applications accordingly.
It works sometimes! However I would really love it to work all the time :)
-The AppleScript apps definitely work and have been successfully launched
-The processing monitor has been printing the 'Val' variable consistently
The issue is that even though processing is reading from the serial port and assigning the IR codes printed there to the 'val' variable, it only sometimes executes the conditional
I added a delay to my arduino sketch to slow down how much data was entering the port and make it easier for Processing to read but it's inconsistent.
Any help would be greatly appreciated!
Arduino code:
#include <boarddefs.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
#include <IRremoteInt.h>
int RECV_PIN = 10;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
Serial.print("Hello");
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(String(results.value,HEX));
delay(100);
irrecv.resume(); // Receive the next value
}
}
Processing Code
import processing.serial.*;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
String Down = "890";
String Up = "8188A2C8";
String CH1 = "E10";
void setup()
{
// I know that the first port in the serial list on my mac
// is Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[2]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);
}
void draw()
{
{
if ( myPort.available() > 0)
{ // If data is available,
val = myPort.readString(); // read it and store it in val
print(val);
if(val.equals(Down) == true)
{launch("/Applications/QlabDown.app");
}
if (val.equals(Up) == true) {
launch("/Applications/QlabUp.app");
}
if (val.equals(CH1) == true) {
launch("/Applications/CH1.app");
}
}
}
}
Processing receive IR codes from the arduino
.... how is Processing receiving infrared signals?