xxxxxxxxxx
41
var serial;
var portName = '/dev/cu.usbmodem1421';
var inData = 0;
let inDataMap;
let currentgrowEllipse = 0.0;
let lastgrowEllipse = 0.0;
function setup() {
createCanvas(300,300);
serial = new p5.SerialPort();
// serial.readLine();
//split
//var currentString = serial.readLine();
// var arrayOfValue = split(currentString, ", ");
// "103","105","200" = [103,105,200]
serial.on('data', serialEvent);
serial.open(portName);
var options = { baudrate: 57600}; // change the data rate to whatever you wish
serial.open(portName, options);
smooth();
}
function serialEvent() {
inData = Number(serial.read());
print("MPH: " + inData);
rectMode(CENTER);
}
function draw() {
background(0,10);
fill(255);
text("MPH: " + inData, 30,30);
let currentgrowEllipse = map(inData, 0, 255, 20, windowWidth);
let lerpEllipse = lerp(currentgrowEllipse, lastgrowEllipse, 0.2);
ellipse(width/2, height/2, lerpEllipse*0.8 + 50);
lastgrowEllipse = currentgrowEllipse;
}