Multiple Channels of Control
Arduino Code:
#define POT_PIN A0
#define BUTTON 12
#define PHOTO A1
void setup() {
// put your setup code here, to run once:
pinMode(POT_PIN, INPUT);
pinMode(BUTTON,INPUT);
pinMode(PHOTO,INPUT);
Serial.begin (9600);
}
void loop() {
// put your main code here, to run repeatedly:
float potValue = analogRead(POT_PIN);
float photoValue = analogRead(PHOTO);
int buttonValue = digitalRead(BUTTON);
Serial.print(potValue);
Serial.print(",");
Serial.print(photoValue);
Serial.print(",");
Serial.println(buttonValue);
delay(50);
}
Processing Code:
import processing.serial.*;
Serial myConnection;
String incomingData = "";
float pot = 0;
float photo = 0;
float button = 0;
void setup(){
size(600,600);
printArray(Serial.list());
myConnection = new Serial(this, Serial.list() [2], 9600);
myConnection.bufferUntil ('\n');
}
void draw(){
if(button > 0){
background(161, 235, 52);
}
else{
background(0);
}
fill(0, pot, pot/2);
circle(width*0.5, height*0.5, pot);
}
void serialEvent(Serial conn){
incomingData = conn.readString();
String[] values = split(trim(incomingData), ",");
pot = map(float(values[0]),0,4095,0,width);
photo = map(float(values[1]),0,4095,0,255);
button = float(values[2]);
printArray(values);
}