Early 3D grid code

So, as part of my research at the Craft Tech Lab, I have been assigned to (attempt) to build an input device. This device would be in the form of a physical grid, in three dimensions, whereby the user would activate various vertices/nodes to intuitively model an object, in 3d, in real time. My first attempt will be to rig up a switch and led at each node (controlled via Arduino), and display the activated nodes in real time in Processing.

Here’s the code I’ve got so far (working with 2 switches):

Processing:


/* grid 3D mapper
 * v.02 - multiple input
 * by Ben Leduc-Mills
*/

import processing.serial.*;

Serial myPort; // the serial port
float buttonId; // the button id we get from arduino if a button is switched

void setup() {

 size(400, 300, P3D);
 //size(400, 300);

 println(Serial.list()); // list available serial ports

 myPort = new Serial(this, Serial.list()[0], 9600);

 myPort.bufferUntil('\n');

 background(255); //set initial background color

}

void draw() {

}

void serialEvent (Serial myPort) {

 //get the button ID
 String inString = myPort.readStringUntil('\n');

 if (inString != null) {

  //trim whitespace
  inString = trim(inString);

  //convert to int so we can use it as a number
  buttonId = float(inString);

  //draw the point
  if ( buttonId == 2 ) {
     stroke(0);
     point (30, 20, -50);
     //ellipse(20, 30, 20 ,20);
    }

  //or cover it up
  else if (buttonId == -2 ) {
    stroke(255);
    point (30, 20, -50);
    //ellipse(20, 30, 20, 20);
  }  

  if (buttonId == 3 ) {
     stroke(0);
     point(50, 20, -50);
  }

  else if (buttonId == -3 ) {
     stroke(255);
     point(50, 20, -50);
  }    

  }

 }

Arduino:


/* 3D grid object placement
 * V.02 - two buttons 
 * Ben Leduc-Mills
*/

// pin assignments won't change
// each point has a switch, an led, and an xyz coordinate
const int button1 = 2;
const int button2 = 3;
//const int led1 = 3;

//var for reading button status
int button1State = 0;
int button2State = 0;

void setup() {

  //start serial communitcation
  Serial.begin(9600);

 //init LED pins as output
 //pinMode(led1, OUTPUT);

 //init button pins as input
 pinMode(button1, INPUT);
 pinMode(button2, INPUT);

}

void loop() {

 // read button states
 button1State = digitalRead(button1);

 if (button1State == HIGH) {
   //digitalWrite(led1, HIGH);
   //Serial.print("button 1:");
   Serial.println(button1);
 }

 else if (button1State == LOW) {
    Serial.println(button1 * -1);
 }

 button2State = digitalRead(button2);

 if (button2State == HIGH) {
  Serial.println(button2);
 }

 else if (button2State == LOW) {
  Serial.println(button2 * -1);
 }

}