This is the code for the Arduino:
int ledPinArray[4] = {29, 30, 31, 32};
int ledTotal = 4;
int potVal = 0;
void setup() {
Serial.begin(9600);
for(int i = 0; i < ledTotal; i++){
pinMode(ledPinArray[i], OUTPUT);
}
}
void loop() {
for(int i = 0; i < ledTotal; i++){
potVal = analogRead(A14);
Serial.write(i);
digitalWrite(ledPinArray[i], HIGH);
delay(potVal);
digitalWrite(ledPinArray[i], LOW);
}
}
This is the code from Processing (I wasn’t sure how to copy the HTML from Processing, it was grayed out for me)
import processing.serial.*;
int inputVal = 0;
Serial teensySerial;
void setup(){
frameRate(30);
size(500, 500);
//printArray(Serial.list());
String usbPortName = Serial.list()[7];
print(usbPortName);
teensySerial = new Serial(this, usbPortName, 9600);
}
void draw(){
if(teensySerial.available() > 0){
inputVal = teensySerial.read();
}
if(inputVal == 0){
background(255, 255, 0);
}
if(inputVal == 1){
background(255, 0, 0);
}
if(inputVal == 2){
background(0, 255, 0);
}
if(inputVal == 3){
background(0, 0, 255);
}
}