Hi everyone! I’m working with a FSR Matrix Array from Sensitronics. I’m trying to make a basic visualizer that displays a black 16x16 grid. When force is detected on the MatrixArray, we’ll shade the corresponding grid cell green, with intensity proportional applied force. I’m obtaining a 16x16 array from Arduino and I want to send this values to Processing via serial in order to visualize the force that is being applied to the sensor. I attach the array that I’m obtaining in Arduino, however I’m having some trouble to display these values in Processing in real time. Can someone help me please? Thanks! In here is an example of the visualizing made by Sensitronics, however their processing code only works for its optimized arduino code and right now I’m working with their not optimized code: https://www.sensitronics.com/tutorials/fsr-matrix-array/page8.php
// 2D Array of objects
import processing.serial.*;
Cell[][] grid;
Serial sPort;
// Number of columns and rows in the grid
int cols = 16;
int rows = 16;
int CELL_SIZE = 40;
char got_byte;
char force;
void setup() {
int port_count = Serial.list().length;
sPort = new Serial(this, Serial.list()[port_count - 1], 115200);
size(640,640);
grid = new Cell[cols][rows];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
// Initialize each object
grid[i][j] = new Cell(i*40,j*40,40,40,i+j);
}
}
}
void draw() {
while(sPort.available() > 0) {
background(0);
// The counter variables i and j are also the column and row numbers and
// are used as arguments to the constructor for each object in the grid.
for (int i = 0; i < cols; i++) {
got_byte = (char) sPort.read();
print(got_byte);
for (int j = 0; j < rows; j++) {
// Oscillate and display each object
grid[i][j].force();
grid[i][j].display();
}
}
}
}
// A Cell object
class Cell {
// A cell object knows about its location in the grid
// as well as its size with the variables x,y,w,h
float x,y; // x,y location
float w,h; // width and height
float angle; // angle for oscillating brightness
// Cell Constructor
Cell(float tempX, float tempY, float tempW, float tempH, float tempAngle) {
x = tempX;
y = tempY;
w = tempW;
h = tempH;
angle = tempAngle;
}
void force() {
got_byte = force;
}
void display() {
stroke(255);
// Color calculated using sine wave
fill(0,0,force);
rect(x,y,w,h);
}
}