Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float offset = 2.23;
- float rot = 0.0;
- import processing.serial.*;
- int yPos =0;
- int xPos = 0;
- boolean colorRed = false;
- boolean colorGreen = false;
- boolean colorBlue = false;
- Serial myPort; // The serial port
- void setup() {
- smooth();
- size(1200,900);
- background(255);
- println(Serial.list());
- myPort = new Serial(this, Serial.list()[0], 115200);
- myPort.bufferUntil('\n');
- }
- void draw() {
- }
- void serialEvent (Serial myPort) {
- String inString = myPort.readStringUntil('\n');
- if (inString != null) {
- // trim off any whitespace:
- inString = trim(inString);
- int xCharPos = inString.indexOf("X");
- int yCharPos = inString.indexOf("Y");
- int pCharPos = inString.indexOf("P");
- String xString = inString.substring(xCharPos + 1, yCharPos);
- String yString = inString.substring(yCharPos + 1, pCharPos);
- String pString = inString.substring(pCharPos + 1, inString.length());
- println(xString + "\t" + yString + "\t" + pString);
- xPos = int(map((Integer.parseInt(xString)), 90, 950, 0, width));
- yPos = int(map((Integer.parseInt(yString)), 920, 120, 0, height));
- int ellipseSize = max(int(map((Integer.parseInt(pString)), 300, 150, 1, 200)),1) ;
- noStroke();
- fill(40,40,40,20);
- if (colorRed)
- fill(255, 0, 0, 20);
- if (colorGreen)
- fill(0,255,0,20);
- if (colorBlue)
- fill(0,0,255,20);
- ellipse(xPos, yPos, ellipseSize, ellipseSize);
- }
- }
- void keyPressed() {
- if (key == 'r' || key == 'R') {
- colorRed =! colorRed;
- colorGreen = false;
- colorBlue = false;
- }
- if (key == 'g' || key == 'G') {
- colorGreen =! colorGreen;
- colorRed = false;
- colorBlue = false;
- }
- if (key == 'b' || key == 'B') {
- colorBlue =! colorBlue;
- colorGreen = false;
- colorRed = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement