Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import libraries
- import java.awt.Frame;
- import java.awt.BorderLayout;
- import processing.serial.*;
- // Serial port to connect to
- String serialPortName = "COM3";
- /* SETTINGS END */
- Serial serialPort; // Serial port object
- void setup() {
- size(900,900);
- noStroke();
- serialPort = new Serial(this, serialPortName, 9600);
- }
- byte[] inBuffer = new byte[50]; // holds serial message
- void draw() {
- background(0);
- if (serialPort.available() > 0) {
- float[] x= new float[2];
- String myString = "";
- try {
- serialPort.readBytesUntil('r', inBuffer);
- }
- catch (Exception e) {
- }
- myString = new String(inBuffer);
- String[] nums = split(myString, ' ');
- try {
- x[0] = float(nums[0]); //X
- x[1] = float(nums[1]); //Y
- }
- catch (Exception e) {
- }
- ellipse(x[0]+500, x[1]+500, 70, 70); //+500 to make the circle in the middle of interface
- }
- }
- Serial.print(xf,DEC); //méthode 1
- Serial.print(" ");
- Serial.print(yf,DEC);
- Serial.print('r');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement