With this code, I want to change the hue of the image and not the background but I’m not sure what I need to change? This is pretty much my first processing project so I’m not of any of the terms or jargon.
Using an arduino and a photoresistor, i’m able to get the background to change but need to change it so the photoresistor changes the hue of the image.
// import the serial library
import processing.serial.*;
// create an instance of the serial library
Serial myPort;
// create an instance of PImage
PImage logo;
// a variable to hold the background color
int bgcolor = 0;
void setup() {
size(1, 1);
surface.setResizable(true);
// set the color mode to Hue/Saturation/Brightness
colorMode(HSB, 255);
// load the Arduino logo into the PImage instance
logo = loadImage("http://www.arduino.cc/arduino_logo.png");
// make the window the same size as the image
surface.setSize(logo.width, logo.height);
// print a list of available serial ports to the Processing status window
println("Available serial ports:");
printArray(Serial.list());
// Tell the serial object the information it needs to communicate with the
// Arduino. Change Serial.list()[0] to the correct port corresponding to
// your Arduino board. The last parameter (e.g. 9600) is the speed of the
// communication. It has to correspond to the value passed to
// Serial.begin() in your Arduino sketch.
myPort = new Serial(this, Serial.list()[1], 9600);
// If you know the name of the port used by the Arduino board, you can
// specify it directly like this.
// port = new Serial(this, "COM1", 9600);
//myPort = new Serial(this, "/dev/ttyACM0", 9600);
}
void draw() {
// if there is information in the serial port
if ( myPort.available() > 0) {
// read the value and store it in a variable
bgcolor = myPort.read();
// print the value to the status window
println(bgcolor);
}
// Draw the background. the variable bgcolor contains the Hue, determined by
// the value from the serial port
background(bgcolor, 255, 255);
// draw the Arduino logo
image(logo, 0, 0);
}
^ Processing code
void setup() {
// starting serial communication. Make sure Processing and Arduino have the same serial baud rate.
Serial.begin(9600);
}
void loop() {
// Sending to the serial connection the analug inputs introcued by the potentiometer.
// As only is possible to send values from 0 to 255, devide de AnalogRead value by 4.
Serial.write(analogRead(A0)/4);
// After sending the byte, let the ADC stabilize.
delay(33);
}
^arduino code
I imagine its fairly simple but I really don’t know what I’m doing. Thanks.