Sunday, June 16, 2013

Processing 2.0 read ADC of Arduino Due via serial

Processing 2.0 read ADC of Arduino Due via serial
Processing 2.0 read ADC of Arduino Due via serial
This exercise of Processing 2.0 code read ADC of Arduino Due via serial. The code in Arduino Due listed in last post.

Code in Processing 2.0 side:
import processing.serial.*;

Serial myArduinoPort;
int data;
int index;

int MAX_INDEX = 400;

void setup(){
  size(400, 300);
  background(255);
   
  //Get serial port for Arduino
  String arduinoPort = Serial.list()[0];
  println(arduinoPort);
  myArduinoPort = new Serial(this, arduinoPort, 19200);
  
  index = 0;
}

void draw(){
  
  while(myArduinoPort.available() > 0){
    data = myArduinoPort.read();
    stroke(0);
    line(index, 300, index, 300-data);
    stroke(255);
    line(index, 0, index, 300-data+1);
    print(data);
    print(".");
    
    index++;
    if(index==MAX_INDEX){
      index = 0;
    }
  }
  println("");
}



download filesDownload the files.

No comments:

Post a Comment