Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- int lf = 10; // Linefeed in ASCII
- String myString = null;
- Serial myPort; // The serial port
- int min, max, current;
- void setup() {
- size(1920, 400);
- //frameRate(200);
- min = 1024;
- max = 0;
- // List all the available serial ports
- println(Serial.list());
- // I know that the first port in the serial list on my mac
- // is always my Keyspan adaptor, so I open Serial.list()[0].
- // Open whatever port is the one you're using.
- myPort = new Serial(this, Serial.list()[0], 9600);
- myPort.clear();
- // Throw out the first reading, in case we started reading
- // in the middle of a string from the sender.
- myString = myPort.readStringUntil(lf);
- myString = null;
- }
- void draw() {
- while (myPort.available () > 0) {
- myString = myPort.readStringUntil(lf);
- if (myString != null) {
- myString = trim(myString);
- current = parseInt(myString);
- if (current > max) max = current;
- if (current < min) min = current;
- background( map(current, min, max, 0, 255), 200, 200 );
- println(current + " " + min + " "+ max);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement