xxxxxxxxxx
49
let circleX;
function setup() {
createCanvas(500, 500);
noFill();
}
function draw() {
background('white');
if (!serialActive) {
console.log('ARDUINO IS NOT CONNECTED'); //output to check if Arduino connected or not
}
if (serialActive) {
fill('violet')
ellipse(map(circleX, 0, 1023, 0, width), height / 2, 100, 100); // using map to make the circle move
console.log(circleX) //output position to check
}
}
function keyPressed() {
if (key == " ")
setUpSerial();
}
function readSerial(data) {
if (data != null) //
circleX = int(data);
}
// ARDUINO CODE
/*
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
}
void loop() {
Serial.println(analogRead(A0));
delay(5);
}
*/