Hello,
can anybody help me with the parameters so that I can see something like the below:
import processing.serial.*;
Serial myPort; // The serial port
int cols = 2;
int rows = 2;
int[][] intensityGrid = new int[rows][cols]; // Intensity values for the grid
float cameraZ = 600; // Camera Z position for depth
void setup() {
size(600, 600, P3D); // Set the window size and enable 3D mode
myPort = new Serial(this, "COM7", 9600); // Replace "COM7" with your Arduino's port
myPort.bufferUntil('\n');
background(255);
}
void draw() {
background(255);
// Set the camera position
lights(); // Add lights for better 3D rendering
translate(width / 2, height / 2); // Move the origin to the center
// Isometric view transformation
rotateX(-PI/6); // Rotate down 30 degrees (in radians)
rotateY(PI/4); // Rotate around Y-axis (45 degrees)
// Set orthographic projection
ortho(-width / 2, width / 2, -height / 2, height / 2, -1000, 1000); // Define the orthographic view
float boxWidth = width / cols / 2; // Reduced width for spacing
float boxDepth = height / rows / 2; // Reduced depth for spacing
float separation = 20; // Separation distance between bars
// Loop through each cell and draw a 3D bar for each touch intensity
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
// Calculate the position for each bar with added separation
float x = map(j, 0, cols, -width / 4, width / 4) + (j * separation);
float y = map(i, 0, rows, -height / 4, height / 4) + (i * separation);
// Map the intensity to the height of the bar (min height = 10, max = 200)
float barHeight = map(intensityGrid[i][j], 0, 1023, 10, 200);
// Move and draw the box (bar)
pushMatrix();
translate(x, y, barHeight / 2); // Move the bar into position
fill(0, 255, 0); // Set the fill color for the bars
stroke(0); // Set the stroke color (black)
strokeWeight(2); // Set the stroke weight (thickness)
box(boxWidth, boxDepth, barHeight); // Create the 3D bar
popMatrix();
}
}
}
void serialEvent(Serial myPort) {
// Read data from the serial port
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
// Debugging: Print incoming string
println("Incoming: " + inString);
if (inString.equals("no_touch")) {
// Clear the entire grid if no touch is detected
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
intensityGrid[i][j] = 0; // Reset intensity
}
}
} else {
String[] data = split(inString, ',');
if (data.length == 3) {
int row = int(data[0]);
int col = int(data[1]);
int intensity = int(data[2]);
// Debugging: Print parsed data
println("Row: " + row + ", Col: " + col + ", Intensity: " + intensity);
// Mark the intensity in the grid
intensityGrid[row][col] = intensity;
}
}
}
}