Exercise 1
Arduino:
void setup() { Serial.begin(9600); while (Serial.available() <= 0) { Serial.println("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.print(sensorValue); Serial.println(); }
P5js:
Exercise 2:
void setup() { Serial.begin(9600); while (Serial.available() <= 0) { Serial.println("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(); // brightness = map(inByte, 0, 1023, 0, 255); analogWrite(5, inByte); Serial.println(inByte); } }
p5js:
Exercise 3:
void setup() { Serial.begin(9600); 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) { // read the incoming byte: int onoff = Serial.read(); analogWrite(5, onoff); int sensorValue = analogRead(A0); Serial.print(sensorValue); Serial.println(); } }
p5js: