const int potPin = A0;
int potVal = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
potVal = analogRead(potPin);
Serial.println(potVal);
delay(10);
}
let serial;
function setup() {
createCanvas(400, 400);
serial = new p5.SerialPort();
serial.open('/dev/tty.usbmodem21401');
serial.on('data', gotData);
}
function gotData() {
let currentString = serial.readLine(); // store the data in a variable
trim(currentString); // get rid of whitespace
if (!currentString) return; // if theaaare's nothing in there, ignore it
console.log(currentString); // print it out
latestData = currentString; // save it to the global variable
}
function draw() {
background(220);
ellipse(width/2,height/2,latestData/3);
}
void setup() {
Serial.begin(9600);
pinMode(5, OUTPUT);
}
void loop() {
if (Serial.available() > 0) { // if there's serial data available
int inByte = Serial.read(); // read it
Serial.write(inByte); // send it back out as raw binary data
analogWrite(5, inByte); // use it to set the LED brightness
}
}
let serial;
// let latestData = "waiting for data";
let inData; // for incoming serial data
let outByte = 0;
function setup() {
createCanvas(400, 400);
serial = new p5.SerialPort();
serial.open('/dev/tty.usbmodem21401');
}
function keyPressed() {
if (key >= 0 && key <= 9) {
// if the user presses 0 through 9
outByte = byte(key * 25); // map the key to a range from 0 to 225
serial.write(outByte); // send it out the serial port
text(key,width/2,height/2);
}
}
function draw() {
background(220);
text(key,width/2,height/2);
textSize(40)
}
in-class
madgwick
https://itp.nyu.edu/physcomp/labs/lab-serial-imu-output-to-p5-js/