I found out that whatever I get in the p5.js sketch as a serial read is one value (52) minus the second value (48) and then multiplied by 10. This would equal 40 which is the serial output set on the Arduino. I am using the p5.serialcontrol application to build a connection from the browser to the serial port:
let serial;
function setup() {
createCanvas(400, 400);
serial = new p5.SerialPort();
serial.open("COM3");
}
function draw() {
background(220);
let data = serial.read();
console.log(data);// prints 48 then 52 repeateadly
}
All digital values and digital signals are just bits, that can be represented and interpreted as numbers (e.g. binary, octal, decimal or hexadecimal). Even text characters are usually stored and transmitted as bits. ASCII is one of the most common translation tables between characters and numeric values.
48 is the ASCII value for character '0' and 52 is the ASCII value for character '4'. The Arduino is sending the string "40" in a loop and the other side is receiving the numeric ASCII values 48 and 52 in a loop.
The other side doesn't know the data type. It only receives bits. You have to tell the program to interpret these bits as ASCII encoded characters.