Hi there. I'm relatively new to Arduino and to Processing, and programming in general. I have a rotary encoder, and what I want to do is play an image sequence with every click of the encoder when its turned. I've gotten pretty close I think. Problem is, that I'm pretty sure that the signal getting sent to Processing isn't quite the same as what's printed in the serial monitor back in Arduino. I also get the error "Could not find a method to load ImageSequence.02 and .03 and .04 and so on with every click of the rotary encoder. What's the story behind this? And is there any easier way to just send the variable "count" from arduino to processing? I really appreciate the help.
This is my Arduino code:
#include <QuadEncoder.h>
int qe1Move=0;
QuadEncoder qe(8,9);
int count = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
qe1Move=qe.hb();
if (qe1Move=='>')
{
count = count + 1;
Serial.println(count);
if (count>46)
{
count = 0;
}
}
if (qe1Move=='<')
{
count = count - 1;
Serial.println(count);
if (count<2)
{
count = 48;
}
}
//Serial.print(char(qe1Move));
//else if (qe1Move=='<')
//Serial.print(char(qe1Move));
//delay(100);
}
This is my code in processing where I'm trying to take the data and make it playback the image sequence:
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
PImage img;
void setup()
{
size(1280, 1280);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
img = loadImage("ImageSequence_01.png");
}
void draw() {
image(img, 0, 0);
if ( myPort.available() > 0) { // If data is available,
val = myPort.read();
loadImage("ImageSequence_" + val);
}
}