Assignment 7.3
Post date: Jul 03, 2010 7:40:13 AM
This one confounds me to no end... I seem to have set everything up right but for some reason the pots I'm using for red and green work fine while the one for blue is unresponsive. I checked the connections 20 times over, the pot itself works plugged into another slot, and everything in the serial port looks exactly as it should, it seems like the processing code is parsing it wrong and not storing the third (blue) value properly, but I can't seem to track down where it messes up. Anyone want to take a look at it and see what's going wrong (Mr. Dickie :D ) ?
ARDUINO CODE
const int pot1 = 5;
const int pot2 = 4;
const int pot3 = 3;
void setup () {
Serial.begin(9600); //begin serial communication at 9600 bps
}
void loop () {
//print to serial port (the /4 is there so it all fits in 1 byte for better speed)
Serial.print((analogRead(pot1)/10));
Serial.print(',');
Serial.print((analogRead(pot2)/10));
Serial.print(',');
Serial.print((analogRead(pot3)/10));
Serial.print('g');
delay(10);
}
PROCESSING CODE
import processing.serial.*;
Serial serPort;
int hueValue[] = new int [3];
void setup () {
size(200, 200);
background(255);
serPort = new Serial(this, Serial.list()[0], 9600);
for(int i=0; i<3; i++) {
hueValue[i]=0;
}
//store string in buffer until punctuation character is hit
serPort.bufferUntil('g'); //'g' has ASCII character code 103
}
void draw () {
ellipseMode(CENTER);
colorMode(RGB, 102);
fill(hueValue[0], hueValue[1], hueValue[2]); //hueValue [2] is the one that won't work
ellipse(height/2, width/2, height/2, width/2);
}
void serialEvent(Serial serPort) {
//store message from buffer in string
String message = serPort.readStringUntil('g');
if(message != null) {
//get rid of 'g's
message.replace('g',' ');
//remove whitespace and other nonsense
message = trim(message);
//set color levels to what's in the serial message
hueValue = int(split(message, ','));
}
}
Also my family's going to Florida for a week (until july 11) and my plane's leaving in about a half hour, I tried to get all the assignments done up until then but no such luck, so that one will have to be a couple days late. This one just kind of tripped me up - I've never been so deeply confused by such little code.