Collecting Data using IO Feeds
My task was to create a sketch that would simulate an existing natural system -
This prompt made me think back to when I was a kid growing up in Texas and watching the fireflies come out on a summer night.
To re-create this system, I used an esp32 breadboard, an internet connected device such as my laptop, a potentiometer (a sensor that logs how much a knob is turned) and a photoresistor ( a sensor that logs how much light is detected). From there I started to collect my data I needed to create this sketch.
Creating Code to Determine Brightness and Swarm Size:
After collecting data I used p5.js code to fetched the values that were collected in the online IO feed and set intervals of 2 seconds between when the values that were being used to update the brightness and count of the fireflies. Then I used pop and push arrays to add and decrease the number for fireflies dynamically. I also used map and constrain to scale my firefly count to keep it within 5-100, I did the same for the brightness to keep it within a realistic range. I kept the placement of the fireflies within the sketch to be random to create a natural feel to the system, thats why I used a Perlin noise movement to keep the movements organic. After that I used draw functions to display the fireflies.
Arduino Code:
AdafruitIO_Feed *potFeed = io.feed("knob-feed");
void setup() {
while(io.status() < AIO_CONNECTED) {
Serial.println();
void loop()
float potVal = analogRead(POTENTIOMETER_PIN);
Serial.print("Sending photoresistor: ");
delay(5000);}
p5.js Code: