Press "Enter" to skip to content

Wk 7: Two-way Serial Communication

Project 2 Concept:

I will cooperate with Echo Tang on this project. More details…


I simulate the corona effects with potentiometer controlling the size of the outermost circle.

Reference:
https://p5js.org/reference/#/p5/shader

Code:

Arduino:

const int potPin = A0;

void setup() {
  Serial.begin(9600); // initialize serial communications
  pinMode(potPin, INPUT);
}
 
void loop() {
  int potentiometer = analogRead(potPin);                  // read the input pin
  int mappedPot = map(potentiometer, 0, 1023, 0, 255); // remap the pot value to fit in 1 byte
  Serial.println(mappedPot);                             // print it out the serial port
  delay(10);  
  // slight delay to stabilize the ADC
}

p5.js

https://editor.p5js.org/Estheeeer/sketches/g1BMzq5tG