Reading serial data
in
Programming Questions
•
1 year ago
Hello I am reading serial from Arduino. They are correct but I want every 3 values to store my data to 3 different variables for R G B color as int. The code below does not work - Why the integers give 0 when I print them but before I convert to int the value is printed correct? can you please help?any hint very appreciated.
- import processing.serial.*;
- Serial port;
- int x=0;
- int y=0;
- int i=0;
- void setup(){
- size(45,45);
- port = new Serial(this,Serial.list()[1], 9600);
- }
- void draw() {
- while (port.available() > 0) {
- String inByteRED = port.readStringUntil(10);
- if (inByteRED != null) {
- int numRed=int(inByteRED);
- println("inByteRED");
- println(numRed);
- }
- String inByteGREEN = port.readStringUntil(10);
- if (inByteGREEN != null) {
- int numGreen=int(inByteGREEN);
- println("inByteGREEN");
- println(numGreen);
- }
- String inByteBLUE = port.readStringUntil(10);
- if (inByteBLUE != null) {
- int numBlue=int(inByteBLUE);
- println("inByteBLUE");
- println(numBlue);
- }
- }
- port.clear();
- }
1