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:
import processing.serial.*; Serial myPort; // the serial port void setup() { size(400, 300, P3D); 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 if (inString != null) { //trim whitespace //convert to int so we can use it as a number //draw the point //or cover it up if (buttonId == 3 ) { else if (buttonId == -3 ) { } } Arduino:
// pin assignments won't change //var for reading button status void setup() { //start serial communitcation //init LED pins as output //init button pins as input } void loop() { // read button states if (button1State == HIGH) { else if (button1State == LOW) { button2State = digitalRead(button2); if (button2State == HIGH) { else if (button2State == LOW) { } |