Exercise 1 –
The ellipse was controlled on the horizontal axis with the potentiometer.
void setup() {
Serial.begin(9600);
while (Serial.available() <= 0) {
Serial.println("0,0"); // send a starting message
delay(300); // wait 1/3 second
}
}
void loop() {
while (Serial.available() > 0) {
// read the incoming byte:
int inByte = Serial.read();
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}
}
https://editor.p5js.org/hindyounus727/sketches/B7U2fCaNp
Exercise 2 –
The LED brightness was controlled by the mouseX value, and is constrained in case it passes the canvas width.
int lightValue = 0;
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(5, OUTPUT);
while (Serial.available() <= 0) {
Serial.println("0,0"); // send a starting message
delay(300); // wait 1/3 second
}
}
void loop() {
while (Serial.available() > 0) {
int lightValue = Serial.read();
analogWrite(5, lightValue);
}
// read the incoming byte:
int inByte = Serial.read();
int sensorValue = analogRead(A0);
Serial.print(sensorValue);
Serial.print(",");
sensorValue = analogRead(A1);
Serial.print(sensorValue);
Serial.println();
}
https://editor.p5js.org/hindyounus727/sketches/SoQkb_ztQ
Exercise 3 –
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
while (Serial.available() <= 0) {
Serial.println("0,0"); // send a starting message
delay(300); // wait 1/3 second
}
}
void loop() {
while (Serial.available() > 0) {
// read the incoming byte:
int inByte = Serial.read();
analogWrite(2, inByte);
int sensorValue = analogRead(A0);
Serial.print(sensorValue);
Serial.println();
}
}
https://editor.p5js.org/mz2934/sketches/kUwzGxtQ5