I'm running standard firmata with this processing code:
/* Grapher
*
* Graphs changing values, refreshing after graph reaches edge. (like an occiloscope)
*
*/
// DEFINTIONS
/* Define speed (X-axis). 1 is the fastest, and is equal to a speed of one value per millisecond.
* i.e. if SPEED = 2 and width is 1000px then width/speed = 500ms per value
*/
int SPEED = 3 ;
// Define Y-axis value.
int Yaxis() {
return arduino.analogRead(3); // Change "mouseY" to Y axis value
}
// End defs
// Program starts here
import cc.arduino.*;
import processing.serial.*;
Arduino arduino;
int lastX, lastY;
int newX, newY;
int high, low;
void setup() {
size(screen.width - 100, screen.height);
background(0);
lastY = height/2;
lastX = 0;
low = height/8;
high = height - low;
arduino = new Arduino(this, Arduino.list()[0], 57600);
}
void draw() {
stroke(255);
newX = millis()/SPEED % width;
if(newX >= width - 20) {
stroke(0);
background(0);
newX = 0;
}
newY = int(map(Yaxis(), 0, 1023, 0, height));
line(lastX, lastY, newX, newY);
stroke(255);
lastX = newX;
lastY = newY;
println(newY);
}
If you didn't already figure it out, it's supposed to be a grapher. I have it graphing analog inputs. Notice how on the last line I am printing my "newY" variable. This always works, but the problem is on the graph. (You can try it if you want.)
Problem 1: values are inverted. A value of about 150 (this is what I get from my electret mic w/ ambient noise) is near the top, and 700 is near the bottom, i.e. it is inverted. Why is this? Is it something in my code, or firmata?
Problem 2: cutoff. You can see that I am mapping the values to fit my laptop's screen. When I hook up a pot to test the graph, I get the above mentioned problem plus another one. Even though I am mapping the low to 0, some values go off the bottom* of the graph Any ideas?
- because of Problem 1.
Thanks!
baum