Created
November 24, 2011 22:16
-
-
Save BlackMac/1392423 to your computer and use it in GitHub Desktop.
Pololu MMA7341 and MMA7361 with Arduino - Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
This is my first ever processing script, so please fork and fix ;) | |
The check for valid data does not work very well ;) | |
*/ | |
import processing.serial.*; | |
Serial myPort; // Create object from Serial class | |
String val; // Data received from the serial port | |
void setup() | |
{ | |
size(200, 200); | |
// I know that the first port in the serial list on my mac | |
// is always my FTDI adaptor, so I open Serial.list()[0]. | |
// On Windows machines, this generally opens COM1. | |
// Open whatever port is the one you're using. | |
String portName = Serial.list()[0]; | |
myPort = new Serial(this, portName, 9600); | |
} | |
int lf = 10; | |
void draw() | |
{ | |
byte[] inBuffer = new byte[28]; | |
if ( myPort.available() > 0) { // If data is available, | |
myPort.readBytesUntil(lf, inBuffer); // read it and store it in val | |
if (inBuffer != null) { | |
String myString = new String(inBuffer); | |
String[] res = myString.split("-"); | |
int x = int(res[0]); | |
if (x>0) { | |
int y = int(res[1]); | |
int z = int(res[2]); | |
background(120); | |
line(100, 100, 100, 100+(x-370)); | |
line(100, 100, 100+(y-370), 100); | |
line(100, 100, 100+(z-450), 100+(z-450)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment