For this lab, I’ll be using the circuit from Intro to Async lab since I have my potentiometer set up.

Potentiometer Pin: A5

Adding the webserial library to p5js

Untitled

Connecting Arduino IDE with p5js editor

p5.js Web Editor

Sketch for Serial communication

void potentioReading(){

   int analogValue = analogRead(pPin);
   int mappedValue = map(analogValue, 0, 1023, 0, 255);
  Serial.write(mappedValue);       
  delay(10);                      

  }

Output on p5js

Output on p5js

Drawing a graph

p5.js Web Editor

Sketch for drawing a graph

p5js output

p5js output

Reading Serial Data as a String

function serialEvent() {
inData = Number(serial.read());
console.log(inData);
print(inData);
}

Untitled

function serialEvent() {
// inData = Number(serial.read());
inData = serial.readLine();
console.log(inData);
print(inData);
}

Untitled