xxxxxxxxxx
68
let ellipseXPos=100;
function setup() {
createCanvas(640, 480);
textSize(18);
}
function draw() {
// one value from Arduino controls the background's red color
background(104, 255, 255);
map(ellipseXPos,0,1023,0,width);
ellipse(ellipseXPos,height/2,100,50);
// the other value controls the text's transparency value
if (!serialActive) {
text("Press Space Bar to select Serial Port", 20, 30);
} else {
text("Connected", 20, 30);
}
// click on one side of the screen, one LED will light up
// click on the other side, the other LED will light up
}
function keyPressed() {
if (key == " ") {
// important to have in order to start the serial connection!!
setUpSerial();
}
}
function readSerial(data) {
////////////////////////////////////
//READ FROM ARDUINO HERE
////////////////////////////////////
if (data != null) {
ellipseXPos=data;
}
}
//Arudino Code
/*
void setup() {
Serial.begin(9600);
}
void loop() {
// wait for data from p5 before doing something
int sensor = analogRead(A0);
delay(1);
Serial.println(sensor);
}
*/