Hello.
I'm fairly new to Arduino & even greener when it comes to Processing, and I've encountered a problem.
I'm trying to do project 14 in the "Arduino projects book". Basically, I want to change the background color of an image using a potentiometer.
Here is my code (including some comments to help myself keep track of things, correct me if they are wrong):
import processing.serial.*;
Serial myPort;
PImage logo;
int bgcolor = 0;
void setup() {
colorMode(HSB, 255);
logo = loadImage("http://www.userlogos.org/files/logos/jumpordie/teamliquid-iphone.png");
size(logo.width, logo.height);
println("Avilable serial ports");
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600); // parameters : which application, which port & what speed
}
void draw() {
if (myPort.available() > 0) { // if(there is something in the buffer)
bgcolor = myPort.read();
println(bgcolor);
}
background(bgcolor, 255, 255); // hue, brightness, saturation. max value 255
image(logo, 0, 0); // image() is used to draw. --- what to draw , x-coordiante to start, y-coordiante to start ---
}
I don't really understand the values I get from myPort.read(). They bounce between 100 and -1, barely depending on how I position the potentiometer. Basically, this results in the background colors shifting constantly, leaving me unable to control them.
So, how can I fix this?
Can someone explain this myPort.read() for me please? I thought that it just took the values from the port I connected my potentiometer to on the Arduino (which is basically just analogRead((A1) / 4); )
Secondly, can I use any image for this, or does it have to be a specific image type?
This image shows the values! http://oi43.tinypic.com/f4iaaa.jpg
Thanks for taking your time to read this, please help!