Created
July 11, 2015 05:38
-
-
Save mithi/750e5acad10e15cff584 to your computer and use it in GitHub Desktop.
accelerometer display with processing and sparki by arcbotics
This file contains hidden or 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
import processing.serial.*; | |
Serial port; | |
String[] values = {"","",""}; | |
PFont font; | |
//Serial.list()[7] is /dev/tty.usbmodem1421 | |
//Serial.list()[4] is /dev/tty.ArcBotics-DevB | |
void setup(){ | |
size(600, 300); | |
String portName = Serial.list()[7]; | |
port = new Serial(this, portName, 9600); | |
port.bufferUntil('a'); | |
font = loadFont("Monaco-50.vlw"); | |
textFont(font, 50); | |
} | |
void parseData(){ | |
String data = ""; | |
int start = 0; | |
int end = 0; | |
println('1'); | |
data = port.readStringUntil('a'); | |
println('2'); | |
if (data != null){ | |
println(data); | |
for (int i=0; i<3; i++){ | |
end = data.indexOf(","); | |
if (end<0){ | |
break; | |
} | |
values[i] = data.substring(0, end); | |
data = data.substring(end+1, data.length()); | |
println(values[i]); | |
} | |
} | |
} | |
void drawAccelValues(){ | |
int x = 70; | |
int y = 100; | |
fill(231, 76, 60); | |
text("accelerometer:", x, y); | |
fill(142, 68, 173); | |
for(int i=0; i < 3; i++){ | |
y = 100 + (i+1)*50; | |
text(values[i], x, y); | |
} | |
} | |
void draw(){ | |
background(40, 40, 40); | |
if (port.available()>0){ | |
parseData(); | |
} | |
drawAccelValues(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment