×

Due to the impacts of the coronavirus outbreak, we are experiencing longer than normal lead times on certain products. We encourage back-ordering out-of-stock items to receive them as soon as possible.

Member #988701

Member Since: May 12, 2017

Country: United States

  • Hello, I've been many problems with the code in Processing, please help me;

    the error is this: ArrayIndexOutOfBoundsException:3.

    P.S. My arduino Uno is COM3. I've tried many ways to solve my problem but I Didn't get it.

    this is my code:

    import processing.serial.*;

    Serial myPort; // The serial port

    int xPos = 1; // horizontal position of the graph

    float height_old = 0;

    float height_new = 0;

    float inByte = 0;

    void setup () {

    // set the window size:

    size(1000, 400);

    // List all the available serial ports

    println(Serial.list()); // Open whatever port is the one you're using.

    myPort = new Serial(this, Serial.list()[3], 9600);

    // don't generate a serialEvent() unless you get a newline character:

    myPort.bufferUntil('\n');

    // set inital background:

    background(0xff);

    }

    void draw () {

    // everything happens in the serialEvent()

    }

    void serialEvent (Serial myPort) {

    // get the ASCII string:

    String inString = myPort.readStringUntil('\n');

    if (inString != null) {

    // trim off any whitespace:
    
    inString = trim(inString);
    
    
    
    // If leads off detection is true notify with blue line
    
    if (inString.equals("!")) { 
    
      stroke(0, 0, 0xff); //Set stroke to blue ( R, G, B)
    
      inByte = 512;  // middle of the ADC range (Flat Line)
    
    }
    
    // If the data is good let it through
    
    else {
    
      stroke(0xff, 0, 0); //Set stroke to red ( R, G, B)
    
      inByte = float(inString); 
    
     }
    
    
    
     //Map and draw the line for new data point
    
     inByte = map(inByte, 0, 1023, 0, height);
    
     height_new = height - inByte; 
    
     line(xPos - 1, height_old, xPos, height_new);
    
     height_old = height_new;
    
    
    
      // at the edge of the screen, go back to the beginning:
    
      if (xPos >= width) {
    
        xPos = 0;
    
        background(0xff);
    
      } 
    
      else {
    
        // increment the horizontal position:
    
        xPos++;
    
      }
    

    }

    }

No public wish lists :(