Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- float penX;
- float penY;
- color bgColor = color( 0 ); // color of background
- color penColor = color( 60, 120, 20 ); // color of our pen
- Serial myPort; // our serial port
- void setup() {
- size( 800, 600 );
- background( bgColor ); // set the background color
- noStroke(); // turn off outline around shapes
- fill( penColor ); // set pen color
- penX = width/2; // starting x position of pen
- penY = height/2; // starting y position of pen
- printArray(Serial.list());
- myPort = new Serial(this, Serial.list()[11], 9600);
- myPort.bufferUntil(10);
- }
- void draw() {
- ellipse( penX, penY, 10, 10 );
- }
- void serialEvent(Serial p) {
- String inString = p.readString(); // read in the string
- //println( inString );
- String pairs[] = split( inString, ';' ); // split up string into pairs
- println(pairs[0]+","+pairs[1]+","+pairs[2]);
- int x = Integer.parseInt(pairs[0]);
- int y = Integer.parseInt(pairs[1]);
- // x value mapping
- penX = map( x, 0, 1023, 0, width);
- // y value mapping
- penY = map( y, 0, 1023, 0, width);
- }
Advertisement
Add Comment
Please, Sign In to add comment