Created
October 20, 2013 08:43
-
-
Save yoggy/7066614 to your computer and use it in GitHub Desktop.
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 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