K
K
Kot Kotov2020-04-24 18:35:13
Arduino
Kot Kotov, 2020-04-24 18:35:13

How to fix the problem with variables in processing?

There is an arduino with a simple output of a variable to the com port, the program is elementary

int i;

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(i);
  i++;
}

There is a program written in processing
import processing.serial.*;

Serial myPort;  
int val; 

PFont font;

void setup()
{
  font = loadFont("Rockwell-CondensedBold-48.vlw");
  size(720, 1280);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw()
{

  background(0);
  textFont(font);

  if ( myPort.available() > 0) 
  {
    val = myPort.read();
  }

  text(val, width/2, height/2);
  println(val);
}

The problem is that when getting data for String everything works adequately, but when getting for int , the val variable rises to 55 and starts counting again.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question