import processing.serial.*;

Serial myPort;
float[] sensorVals = {0, 0, 0};
int threshold = 500;    // adjust based on your readings

void setup() {
  size(500, 500);
  background(0);
  
  // List ports once in the console so you can pick the right one
  printArray(Serial.list());
  
  // 👇 Change [0] to the correct index from the printed list if needed
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
}

void draw() {
  background(30);
  
  int zoneWidth = width / 3;

  for (int i = 0; i < 3; i++) {
    float val = sensorVals[i];
    boolean active = val > threshold;

    // color: bright when touched, dim otherwise
    if (active) {
      fill(255, 180, 0);   // active
    } else {
      fill(80);            // idle
    }
    noStroke();
    rect(i * zoneWidth, 0, zoneWidth, height);

    // text overlay with value
    fill(255);
    textAlign(CENTER, CENTER);
    text("Pad " + (i+1) + "\n" + int(val), 
         i * zoneWidth + zoneWidth/2, 
         height/2);
  }
}

// Called whenever a full line arrives over serial
void serialEvent(Serial p) {
  String in = p.readStringUntil('\n');
  if (in == null) return;
  
  in = trim(in);
  String[] parts = split(in, ',');
  if (parts.length == 3) {
    for (int i = 0; i < 3; i++) {
      sensorVals[i] = float(parts[i]);
    }
  }
}
