1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Analog input goes to processing graph.

Posted at

analog input to serial

const int SENSOR = A0;
const int LED = 13;

int val = 0;
int max = 0;

void setup() {
  Serial.begin(9600);
  pinMode(SENSOR, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  val = analogRead(SENSOR);

  if (val > max) {
    max = val;
  }
  
  String space = " ";

  Serial.println(val);

  if (val > 1) {
    digitalWrite(LED, HIGH);
  } else {
    digitalWrite(LED, LOW);
  }
  
  delay(10);

}

serial input to graph



import processing.serial.*;

Serial myPort;

int xPos = 1;
float max = 0;
float cur = 0;

void setup() {
  size(720, 240);
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[2], 9600);
  myPort.bufferUntil('\n');
  background(58,179,254);
}

void draw() {
}

void serialEvent(Serial myPort) {
  String inString = myPort.readStringUntil('\n');
  if (inString != null) {
    inString = trim(inString);
    float inByte = float(inString);
    inByte = map(inByte, 0, 50, 0, height);
    
    stroke(13,0,192);
    line(xPos, height, xPos, height - inByte);
    
    if (xPos >= width) {
      xPos = 0;
      max = 0;
      background(58,179,254);
    } else {
      xPos++;
    }
    
    if (inByte > max) {
      stroke(58,179,254);
      line(0, height - max, width, height - max);
      max = inByte;
      cur = height - inByte;
      stroke(13,0,192);
      line(0, cur, width, cur);
    } 
  }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?