Hello everyone, I've only been working with the Arduino for about a week and Processing much less then that. I'm working very hard to teach myself how it all works for a big project I want to do in the future, but I really want to understand it, not just follow tutorials and be satisfied.
Recently I followed a tutorial by Jeremy Blum about controlling the a single color of your screen using a pot and Processing.
I followed it and got it working well, but then I wanted to push it to control RGB color using three pots. I made the Arduino code and got it outputting serial communication stating each RGB value separated by a char.
ie.. R255G255B0
I'm not sure if I'm going about this in the right way or not but I'm completely stuck on the Processing side. There are a few texts out there about it but they are as clear as mud to me. I just included the base code without trying to read each value, all attempts were major failures. Any help would be greatly appreciated. Thank you very much.
Arduino Code:
int RedPotPin = 0;
int GreenPotPin= 1;
int BluePotPin= 2;
void setup()
{
pinMode(RedPotPin, INPUT);
pinMode(GreenPotPin, INPUT);
pinMode(BluePotPin, INPUT);
Serial.begin(9600);
}
void loop()
{
int RedVal = map(analogRead(RedPotPin), 0, 1023, 0, 255);
int GreenVal = map(analogRead(GreenPotPin), 33, 972, 0, 255);
int BlueVal = map(analogRead(BluePotPin), 0, 1023, 0, 255);
Serial.print('R');
Serial.print(RedVal);
Serial.print("G");
Serial.print(GreenVal);
Serial.print("B");
Serial.print(BlueVal);
Serial.println();
delay(100);
}
Processing Code:
import processing.serial.*;
Serial port;
float brightnessRed = 0;
float brightnessGreen = 0;
float brightnessBlue = 0;
void setup()
{
size (500,500);
port = new Serial(this, "COM3", 9600);
port.bufferUntil('\n');
}
void draw()
{
background(brightnessRed,brightnessGreen,brightnessBlue);
}
void serialEvent (Serial port)
{
brightnessRed = float(port.readStringUntil('G'));
}
P.S. I know this has no real world application, I'm just trying it to learn.