Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add angle meter sketch

  • Loading branch information...
commit f75112464306a34c8ef66b3480a9cb2f37fa2068 1 parent e1a4b8c
Leandro A. F. Pereira authored March 07, 2010
87  Transferidor/Transferidor.pde
... ...
@@ -0,0 +1,87 @@
  1
+import processing.serial.*;
  2
+
  3
+PrintWriter outputFile = null;
  4
+Serial serialPort;
  5
+float angle = 0.0f;
  6
+PFont font;
  7
+PImage bg;
  8
+
  9
+float zeroAngle = 90.0f;
  10
+float range = 180.0f;
  11
+float maxValue = 180.0f;
  12
+
  13
+int outputFileNo = 0;
  14
+
  15
+void setup() {
  16
+  size(498, 272);
  17
+  noStroke();
  18
+
  19
+  println(Serial.list());
  20
+
  21
+  String portName = Serial.list()[0];
  22
+  serialPort = new Serial(this, portName, 9600);
  23
+  serialPort.bufferUntil(10);
  24
+
  25
+  font = loadFont("LucidaBright-DemiItalic-48.vlw");
  26
+  textFont(font, 30);
  27
+  fill(0, 102, 153);
  28
+
  29
+  bg = loadImage("transferidor8115.jpg");
  30
+
  31
+  strokeWeight(3);
  32
+  smooth();
  33
+}
  34
+
  35
+void draw() {
  36
+  int x1 = 250;
  37
+  int x2 = x1; 
  38
+  int y1 = 244; 
  39
+  int y2 = y1;
  40
+  float angleToUse = zeroAngle - range * (angle / maxValue);
  41
+
  42
+  x2 += (int)( cos(radians(angleToUse))*250);
  43
+  y2 -= (int)( sin(radians(angleToUse))*244);
  44
+
  45
+  background(bg);
  46
+  stroke(255, 0, 0);
  47
+  line(x1, y1, x2, y2);
  48
+  ellipse(x1, y1, 5, 5);
  49
+  ellipse(x2, y2, 5, 5);
  50
+
  51
+  text(angle, 260, 240);
  52
+  
  53
+  if (outputFile != null) {
  54
+    outputFile.println(angle + 90);
  55
+  }
  56
+}
  57
+
  58
+void keyPressed() {
  59
+  if (key == RETURN || key == ENTER) {
  60
+      if (outputFile == null) {
  61
+          outputFileNo++;
  62
+
  63
+          outputFile = createWriter(Integer.toString(outputFileNo) + ".txt");
  64
+          println("output file is: " + Integer.toString(outputFileNo) + ".txt");
  65
+      } else {
  66
+          println("closing output file: " + Integer.toString(outputFileNo) + ".txt");
  67
+          outputFile.flush();
  68
+          outputFile.close();
  69
+          outputFile = null;
  70
+      }
  71
+  }
  72
+}
  73
+
  74
+void serialEvent(Serial serialPort) {
  75
+  String s = serialPort.readString();
  76
+
  77
+  try {
  78
+    angle = Float.parseFloat(s);
  79
+  } 
  80
+  catch (java.lang.NumberFormatException e) {
  81
+    angle = 0;
  82
+  }
  83
+
  84
+  angle = -angle;
  85
+}
  86
+
  87
+
BIN  Transferidor/data/LucidaBright-DemiItalic-48.vlw
Binary file not shown
BIN  Transferidor/data/transferidor8115.jpg

0 notes on commit f751124

Please sign in to comment.
Something went wrong with that request. Please try again.