Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created October 20, 2013 08:43
Show Gist options
  • Select an option

  • Save yoggy/7066614 to your computer and use it in GitHub Desktop.

Select an option

Save yoggy/7066614 to your computer and use it in GitHub Desktop.
import processing.serial.*;
Serial serial;
PFont font;
void setup() {
size(600, 600);
serial = new Serial(this, "/dev/cu.usbmodem1421", 115200);
font = createFont("Impact", 32);
}
int sensor_val;
int read_sensor_val() {
while (serial.available () > 0) {
String str = serial.readStringUntil(10);
if (str != null) {
str = trim(str);
sensor_val = int(str);
}
}
return sensor_val;
}
void draw() {
int val = read_sensor_val();
background(0, 0, 64);
fill(255,255,255);
noStroke();
textFont(font);
text("val=" + val, 30, 30);
fill(255, 255, 0);
noStroke();
float p = val / 1023.0f;
float angle = PI * p;
arc(300, 300, 400, 400, -angle, angle, PIE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment