How to Display Data with Images

Portion of Arduino Code

if(angle > -22.5 && angle < 22.5){
  Serial.println('N');
  }
  else if(angle > 22.5 && angle < 67.5){
  Serial.println("NE");
  }
  else if(angle > 67.5 && angle< 112.5){
  Serial.println('E');
  }
  else if(angle > 112.5 && angle < 157.5){
  Serial.println("SE");
  }
  else if(angle > 157.5 || angle < -157.5){
  Serial.println('S');
  }
  else if(angle < -22.5 && angle > -67.5){
  Serial.println("NW");
  }
  else if(angle < -67.5 && angle > -112.5){
  Serial.println('W');
  }
  else if(angle < -112.5 && angle > -157.5){
  Serial.println("SW");
  }

Processing

import processing.serial.*;
PImage img;


Serial myPort;    // The serial port:
PFont myFont;     // The display font:
String inString;  // Input string from serial port:
int lf = 10;      // ASCII linefeed

void setup() {
  img = loadImage("arrow2.png");
  size(800,600);
  // Make your own font. It's fun!
  myFont = loadFont("Serif-48.vlw");
  textFont(myFont, 35);
  // List all the available serial ports:
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[3], 2400);
  myPort.bufferUntil(lf);
}

void draw() {

  background(0);
  while (myPort.available()>0){
  String inBuffer = myPort.readString();
  if(inBuffer == "N"){
    set(100,100,img);
  }
}
}

Image does not display. Can anyone tell me what I am doing wrong and how I can fix it?

Perhaps in Draw() where you check:

if(inBuffer == "N")

the value of inBuffer is "NNNNNNNNNNNNNNN" ?

Try checking only the first character, or processing the string to check every character.

How would I go about doing that? I am very new to Processing and Arduino.

Well, I've never used Processing, but I think what you should do is process each incoming character one at a time instead of reading an entire string.

Right now you are using:

  String inBuffer = myPort.readString();

which is going to read all the characters in the serial buffer. Depending on how fast they are being sent and how long it has been since you read the buffer, that could be a string of several characters.

I would try reading the buffer one character at a time:

  char inChar = myPort.readChar();