Root – Lya Li – Andy Garcia

A. PROJECT TITLE – YOUR NAME – YOUR INSTRUCTOR’S NAME

Root – Lya Li – Andy Garcia

B. CONCEPTION AND DESIGN:

We’ve chosen to focus on nostalgia in our final project. No matter what life stage you are in, stressors are always there, often prompting a longing for simpler times. Reflecting on the carefree, nostalgic moments of our youth, when our biggest worry was what we’d have for lunch, serves as a reminder that these concerns are not individualized but rather part of a broader experience, particularly prevalent among college students from our observations.

At the surface level, the aim of our project is to make people feel the emotion of being nostalgic in the hopes that it will destress them and remind them of simpler times. However, looking further, there is a deeper meaning. The deeper meaning of our project extends beyond simply evoking nostalgia; it’s about reconnecting with our roots, rediscovering our true selves, and finding motivation amid life’s challenges. By tapping into nostalgic emotions, we aim to offer solace and inspiration, reminding individuals of their journey, their origins, and the intrinsic reasons driving their pursuits. In essence, it’s about navigating the present by drawing strength from the past, ultimately fostering resilience and personal growth in the face of challenges.

C. FABRICATION AND PRODUCTION:

We were using touch sensors as our first plan, which created most of the pain in our production process. Metal foils and long wires were both a must and created a lot of consequences which required tons of debouncing code, but this could also create a lot of issues with the audio. After spending hours of time and multiple attempts, the final solution was to change to light sensors, which required slightly more adjustment but were a lot easier to understand and control.

Going deep into the code, we were using serial communications between Arduino and Processing. The Arduino reads values from the 4 sensors and controls the LED strips, while Processing is controlled by the Arduino values and does the audio amplification analysis, and eventually, it sends values to Arduino to determine how exactly the LEDs were lit up.

D. CONCLUSIONS:

We received a lot of positive comments for our teachers, classmates, and audiences. In my previous reading response assignment, I was saying that a good interactive project should offer abundant context and materials for users to create their unique work. So I think that we did pretty well in this project because we went through nearly every situation that might break the experience and found ways to save them. 

From the technical perspective, the code could have less repetition and become a lot simpler if we used good naming methods, arrays, and “for” loops. (I blame this on the unstable touch sensors because they took us too much time. T_T) Based on this undone simplifying work, we could’ve made the project a lot more dynamic because now it’s like just a fancy switch. For example, we could’ve added more sensors in different parts of our box to add more interaction with the audio or the light.

Another thought undone is about whether to add more cooperation elements to the project. From our final presentation, we received a lot of suggestions like adding music to the audio or making the light effects fancier if more people participated in this project. I do agree that adding collective elements to our project would be very cool, but that was different from our first idea, as we wanted to make this project an individual experience that encouraged people to go back to our own childhood memories. I suppose it’s our project layout that creates this confusion: we are letting multiple users control only one cloud. If we want it to be an individual experience, we should also separate the responding component (which is the cloud in this case) into different parts. This gave me a lesson that we should consider more about how the concept and the production cooperate.

E. DISASSEMBLY:

T_T

F. APPENDIX

Visual documentation:

Video1         Video2          Video3

Arduino code:

/// @file    DemoReel100.ino
/// @brief   FastLED "100 lines of code" demo reel, showing off some effects
/// @example DemoReel100.ino
#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define FRAMES_PER_SECOND 120
#define NUM_LEDS 120  // How many leds on your strip?
#define DATA_PIN0 3
CRGB ledsG[NUM_LEDS];
#define DATA_PIN1 5
CRGB ledsP[NUM_LEDS];
#define DATA_PIN2 6
CRGB ledsR[NUM_LEDS];
#define DATA_PIN3 13
CRGB ledsY[NUM_LEDS];
// constants won't change. They're used here to set pin numbers:
const int buttonPin0 = A0;  // the number of the pushbutton pin
const int buttonPin1 = A1;  // the number of the pushbutton pin
const int buttonPin2 = A2;  // the number of the pushbutton pin
const int buttonPin3 = A4;  // the number of the pushbutton pin
int button0 = 0;
int button1 = 0;
int button2 = 0;
int button3 = 0;
int buttonState0 = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
float volume = 0;
#define NUM_OF_VALUES_FROM_PROCESSING 1 /* CHANGE THIS ACCORDING TO YOUR PROJECT */
/* This array stores values from Processing */
int processing_values[NUM_OF_VALUES_FROM_PROCESSING];
void setup() {
  Serial.begin(115200);
  FastLED.addLeds<NEOPIXEL, DATA_PIN0>(ledsG, NUM_LEDS);
  FastLED.addLeds<NEOPIXEL, DATA_PIN1>(ledsP, NUM_LEDS);
  FastLED.addLeds<NEOPIXEL, DATA_PIN2>(ledsR, NUM_LEDS);
  FastLED.addLeds<NEOPIXEL, DATA_PIN3>(ledsY, NUM_LEDS);
  FastLED.setBrightness(100);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin0, INPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
}
// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
uint8_t gCurrentPatternNumber = 0;  // Index number of which pattern is current
uint8_t gHue = 0;                   // rotating "base color" used by many of the patterns
void loop() {
  getSerialData();
  volume = processing_values[0];
  // read the state of the pushbutton value:
  button0 = analogRead(buttonPin0);
  if (button0 > 450) {
    buttonState0 = 1;
  } else {
    buttonState0 = 0;
  }
  button1 = analogRead(buttonPin1);
  if (button1 > 450) {
    buttonState1 = 1;
  } else {
    buttonState1 = 0;
  }
  button2 = analogRead(buttonPin2);
  if (button2 > 400) {
    buttonState2 = 1;
  } else {
    buttonState2 = 0;
  }
  button3 = analogRead(buttonPin3);
  if (button3 > 400) {
    buttonState3 = 1;
  } else {
    buttonState3 = 0;
  }
  Serial.print(buttonState0);
  Serial.print(",");
  Serial.print(buttonState1);
  Serial.print(",");
  Serial.print(buttonState2);
  Serial.print(",");
  Serial.print(buttonState3);
  Serial.print(",");
  Serial.print(button0);
  Serial.print(",");
  Serial.print(button1);
  Serial.print(",");
  Serial.print(button2);
  Serial.print(",");
  Serial.print(button3);
  Serial.println();
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  for (int i = 0; i < NUM_LEDS / 4; i = i + 1) {
    if (buttonState0 == 1 && buttonState1 == 1 && buttonState2 == 1 && buttonState3 == 1) {
      // FastLED's built-in rainbow generator
      fill_rainbow(ledsG, NUM_LEDS, gHue, 7);
      fill_rainbow(ledsP, NUM_LEDS, gHue, 7);
      fill_rainbow(ledsR, NUM_LEDS, gHue, 7);
      fill_rainbow(ledsY, NUM_LEDS, gHue, 7);
      addGlitter(80);
    } else {
      if (buttonState0 == 1) {
        if (i < NUM_LEDS * (volume / 100)) {
          int randomV = random(-65, 65);
          ledsG[i] = CRGB(76, 255 - i * 2 + randomV, 19);
          ledsP[i] = CRGB(76, 255 - i * 2 + randomV, 19);
          ledsR[i] = CRGB(76, 255 - i * 2 + randomV, 19);
          ledsY[i] = CRGB(76, 255 - i * 2 + randomV, 19);
        } else {
          ledsG[i] = CRGB(0, 0, 0);
          ledsP[i] = CRGB(0, 0, 0);
          ledsR[i] = CRGB(0, 0, 0);
          ledsY[i] = CRGB(0, 0, 0);
        }
      } else {
        ledsG[i] = CRGB(0, 0, 0);
        ledsP[i] = CRGB(0, 0, 0);
        ledsR[i] = CRGB(0, 0, 0);
        ledsY[i] = CRGB(0, 0, 0);
      }
      if (buttonState1 == 1) {
        if (i < NUM_LEDS * (volume / 100)) {
          int randomV = random(-65, 65);
          ledsG[i + NUM_LEDS / 4] = CRGB(186, 40, 195 - i * 2 + randomV);
          ledsP[i + NUM_LEDS / 4] = CRGB(186, 40, 195 - i * 2 + randomV);
          ledsR[i + NUM_LEDS / 4] = CRGB(186, 40, 195 - i * 2 + randomV);
          ledsY[i + NUM_LEDS / 4] = CRGB(186, 40, 195 - i * 2 + randomV);
        } else {
          ledsG[i + NUM_LEDS / 4] = CRGB(0, 0, 0);
          ledsP[i + NUM_LEDS / 4] = CRGB(0, 0, 0);
          ledsR[i + NUM_LEDS / 4] = CRGB(0, 0, 0);
          ledsY[i + NUM_LEDS / 4] = CRGB(0, 0, 0);
        }
      } else {
        ledsG[i + NUM_LEDS / 4] = CRGB(0, 0, 0);
        ledsP[i + NUM_LEDS / 4] = CRGB(0, 0, 0);
        ledsR[i + NUM_LEDS / 4] = CRGB(0, 0, 0);
        ledsY[i + NUM_LEDS / 4] = CRGB(0, 0, 0);
      }
      if (buttonState2 == 1) {
        if (i < NUM_LEDS * (volume / 100)) {
          int randomV = random(-65, 65);
          ledsG[i + NUM_LEDS / 2] = CRGB(255 - i * 2 + randomV, 25, 19);
          ledsP[i + NUM_LEDS / 2] = CRGB(255 - i * 2 + randomV, 25, 19);
          ledsR[i + NUM_LEDS / 2] = CRGB(255 - i * 2 + randomV, 25, 19);
          ledsY[i + NUM_LEDS / 2] = CRGB(255 - i * 2 + randomV, 25, 19);
        } else {
          ledsG[i + NUM_LEDS / 2] = CRGB(0, 0, 0);
          ledsP[i + NUM_LEDS / 2] = CRGB(0, 0, 0);
          ledsR[i + NUM_LEDS / 2] = CRGB(0, 0, 0);
          ledsY[i + NUM_LEDS / 2] = CRGB(0, 0, 0);
        }
      } else {
        ledsG[i + NUM_LEDS / 2] = CRGB(0, 0, 0);
        ledsP[i + NUM_LEDS / 2] = CRGB(0, 0, 0);
        ledsR[i + NUM_LEDS / 2] = CRGB(0, 0, 0);
        ledsY[i + NUM_LEDS / 2] = CRGB(0, 0, 0);
      }
      if (buttonState3 == 1) {
        if (i < NUM_LEDS * (volume / 100)) {
          int randomV = random(-65, 65);
          ledsG[i + 3 * NUM_LEDS / 4] = CRGB(20, 55, 255 - i * 2 + randomV);
          ledsP[i + 3 * NUM_LEDS / 4] = CRGB(20, 55, 255 - i * 2 + randomV);
          ledsR[i + 3 * NUM_LEDS / 4] = CRGB(20, 55, 255 - i * 2 + randomV);
          ledsY[i + 3 * NUM_LEDS / 4] = CRGB(20, 55, 255 - i * 2 + randomV);
        } else {
          ledsG[i + 3 * NUM_LEDS / 4] = CRGB(0, 0, 0);
          ledsP[i + 3 * NUM_LEDS / 4] = CRGB(0, 0, 0);
          ledsR[i + 3 * NUM_LEDS / 4] = CRGB(0, 0, 0);
          ledsY[i + 3 * NUM_LEDS / 4] = CRGB(0, 0, 0);
        }
      } else {
        ledsG[i + 3 * NUM_LEDS / 4] = CRGB(0, 0, 0);
        ledsP[i + 3 * NUM_LEDS / 4] = CRGB(0, 0, 0);
        ledsR[i + 3 * NUM_LEDS / 4] = CRGB(0, 0, 0);
        ledsY[i + 3 * NUM_LEDS / 4] = CRGB(0, 0, 0);
      }
    }
  }
  FastLED.show();
}
/* Receive Serial data from Processing */
/* You won't need to change this code  */
void getSerialData() {
  static int tempValue = 0;  // the "static" makes the local variable retain its value between calls of this function
  static int tempSign = 1;
  static int valueIndex = 0;
  while (Serial.available()) {
    char c = Serial.read();
    if (c >= '0' && c <= '9') {
      // received a digit:
      // multiply the current value by 10, and add the character (converted to a number) as the last digit
      tempValue = tempValue * 10 + (c - '0');
    } else if (c == '-') {
      // received a minus sign:
      // make a note to multiply the final value by -1
      tempSign = -1;
    } else if (c == ',' || c == '\n') {
      // received a comma, or the newline character at the end of the line:
      // update the processing_values array with the temporary value
      if (valueIndex < NUM_OF_VALUES_FROM_PROCESSING) {  // should always be the case, but double-check
        processing_values[valueIndex] = tempValue * tempSign;
      }
      // get ready for the new data by resetting the temporary value and sign
      tempValue = 0;
      tempSign = 1;
      if (c == ',') {
        // move to dealing with the next entry in the processing_values array
        valueIndex = valueIndex + 1;
      } else {
        // except when we reach the end of the line
        // go back to the first entry in this case
        valueIndex = 0;
      }
    }
  }
}
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
void addGlitter(fract8 chanceOfGlitter) {
  if (random8() < chanceOfGlitter) {
    ledsG[random16(NUM_LEDS)] += CRGB::White;
    ledsP[random16(NUM_LEDS)] += CRGB::White;
    ledsR[random16(NUM_LEDS)] += CRGB::White;
    ledsY[random16(NUM_LEDS)] += CRGB::White;
  }
}
 

Processing:

import processing.serial.*;

Serial serialPort;

int NUM_OF_VALUES_FROM_PROCESSING = 1;  /* CHANGE THIS ACCORDING TO YOUR PROJECT */
/* This array stores values you might want to send to Arduino */
float processing_values[] = new float[NUM_OF_VALUES_FROM_PROCESSING];

int NUM_OF_VALUES_FROM_ARDUINO = 8;  /* CHANGE THIS ACCORDING TO YOUR PROJECT */
/* This array stores values from Arduino */
int arduino_values[] = new int[NUM_OF_VALUES_FROM_ARDUINO];


import processing.sound.*;

SoundFile soundG;
SoundFile soundGP;
SoundFile soundGPR;
SoundFile soundGPRY;
SoundFile soundGPY;
SoundFile soundGR;
SoundFile soundGRY;
SoundFile soundGY;
SoundFile soundP;
SoundFile soundPR;
SoundFile soundPRY;
SoundFile soundPY;
SoundFile soundR;
SoundFile soundRY;
SoundFile soundY;

Amplitude analysisG;
Amplitude analysisGP;
Amplitude analysisGPR;
Amplitude analysisGPRY;
Amplitude analysisGPY;
Amplitude analysisGR;
Amplitude analysisGRY;
Amplitude analysisGY;
Amplitude analysisP;
Amplitude analysisPR;
Amplitude analysisPRY;
Amplitude analysisPY;
Amplitude analysisR;
Amplitude analysisRY;
Amplitude analysisY;

float volume = 0;

/*
import java.util.ArrayList;

ArrayList<Ball> gballs = new ArrayList<Ball>();
ArrayList<Ball> pballs = new ArrayList<Ball>();
ArrayList<Ball> rballs = new ArrayList<Ball>();
ArrayList<Ball> yballs = new ArrayList<Ball>();
*/

void setup() {
  fullScreen();

  printArray(Serial.list());
  // put the name of the serial port your Arduino is connected
  // to in the line below - this should be the same as you're
  // using in the "Port" menu in the Arduino IDE
  serialPort = new Serial(this, "COM5", 115200);


  // load and play a sound file in a loop
  // sound = new SoundFile(this, "song.mp3");

  soundG= new SoundFile(this, "G.mp3");
  soundGP= new SoundFile(this, "GP.mp3");
  soundGPR= new SoundFile(this, "GPR.mp3");
  soundGPRY= new SoundFile(this, "GPRY.mp3");
  soundGPY= new SoundFile(this, "GPY.mp3");
  soundGR= new SoundFile(this, "GR.mp3");
  soundGRY= new SoundFile(this, "GRY.mp3");
  soundGY= new SoundFile(this, "GY.mp3");
  soundP= new SoundFile(this, "P.mp3");
  soundPR= new SoundFile(this, "PR.mp3");
  soundPRY= new SoundFile(this, "PRY.mp3");
  soundPY= new SoundFile(this, "PY.mp3");` 
  soundR= new SoundFile(this, "R.mp3");
  soundRY= new SoundFile(this, "RY.mp3");
  soundY= new SoundFile(this, "Y.mp3");

  // create the Amplitude analysis object
  analysisG = new Amplitude(this);
  analysisGP = new Amplitude(this);
  analysisGPR = new Amplitude(this);
  analysisGPRY = new Amplitude(this);
  analysisGPY = new Amplitude(this);
  analysisGR = new Amplitude(this);
  analysisGRY = new Amplitude(this);
  analysisGY = new Amplitude(this);
  analysisP = new Amplitude(this);
  analysisPR = new Amplitude(this);
  analysisPRY = new Amplitude(this);
  analysisPY = new Amplitude(this);
  analysisR = new Amplitude(this);
  analysisRY = new Amplitude(this);
  analysisY = new Amplitude(this);

  // use the soundfile as the input for the analysis
  analysisG.input(soundG);
  analysisGP.input(soundGP);
  analysisGPR.input(soundGPR);
  analysisGPRY.input(soundGPRY);
  analysisGPY.input(soundGPY);
  analysisGR.input(soundGR);
  analysisGRY.input(soundGRY);
  analysisGY.input(soundGY);
  analysisP.input(soundP);
  analysisPR.input(soundPR);
  analysisPRY.input(soundPRY);
  analysisPY.input(soundPY);
  analysisR.input(soundR);
  analysisRY.input(soundRY);
  analysisY.input(soundY);
   
  surface.setTitle("Processing Sketch");
}


void draw() {
  //background(255,255,255,10);
  // receive the values from Arduino
  getSerialData();

  // arduino_values[0] are the values from the 1 touch sensor, and so on

  volume = 0;

  if (arduino_values[0] == 1 && arduino_values[1] == 1 && arduino_values[2] == 1 && arduino_values[3] == 1) {
    volume = int(500 * analysisGPRY.analyze());
    if (soundGPRY.isPlaying() == false) {
      soundGPRY.play();
    }
  } else {
    soundGPRY.pause();
  }
  if (arduino_values[0] == 1 && arduino_values[1] == 1 && arduino_values[2] == 1 && arduino_values[3] == 0) {
    volume = int(500 * analysisGPR.analyze());
    if (soundGPR.isPlaying() == false) {
      soundGPR.play();
    }
  } else {
    soundGPR.pause();
  }
  if (arduino_values[0] == 1 && arduino_values[1] == 1 && arduino_values[2] == 0 && arduino_values[3] == 1) {
    volume = int(500 * analysisGPY.analyze());
    if (soundGPY.isPlaying() == false) {
      soundGPY.play();
    }
  } else {
    soundGPY.pause();
  }
  if (arduino_values[0] == 1 && arduino_values[1] == 1 && arduino_values[2] == 0 && arduino_values[3] == 0) {
    volume = int(500 * analysisGP.analyze());
    if (soundGP.isPlaying() == false) {
      soundGP.play();
    }
  } else {
    soundGP.pause();
  }
  if (arduino_values[0] == 1 && arduino_values[1] == 0 && arduino_values[2] == 1 && arduino_values[3] == 1) {
    volume = int(500 * analysisGRY.analyze());
    if (soundGRY.isPlaying() == false) {
      soundGRY.play();
    }
  } else {
    soundGRY.pause();
  }
  if (arduino_values[0] == 1 && arduino_values[1] == 0 && arduino_values[2] == 1 && arduino_values[3] == 0) {
    volume = int(500 * analysisGR.analyze());
    if (soundGR.isPlaying() == false) {
      soundGR.play();
    }
  } else {
    soundGR.pause();
  }
  if (arduino_values[0] == 1 && arduino_values[1] == 0 && arduino_values[2] == 0 && arduino_values[3] == 1) {
    volume = int(500 * analysisGY.analyze());
    if (soundGY.isPlaying() == false) {
      soundGY.play();
    }
  } else {
    soundGY.pause();
  }
  if (arduino_values[0] == 1 && arduino_values[1] == 0 && arduino_values[2] == 0 && arduino_values[3] == 0) {
    volume = int(500 * analysisG.analyze());
    if (soundG.isPlaying() == false) {
      soundG.loop();
    }
  } else {
    soundG.pause();
  }
  if (arduino_values[0] == 0 && arduino_values[1] == 1 && arduino_values[2] == 1 && arduino_values[3] == 1) {
    volume = int(500 * analysisPRY.analyze());
    if (soundPRY.isPlaying() == false) {
      soundPRY.play();
    }
  } 
  else {
    soundPRY.pause();
  }
  if (arduino_values[0] == 0 && arduino_values[1] == 1 && arduino_values[2] == 1 && arduino_values[3] == 0) {
    volume = int(500 * analysisPR.analyze());
    if (soundPR.isPlaying() == false) {
      soundPR.play();
    }
  } else {
    soundPR.pause();
  }
  if (arduino_values[0] == 0 && arduino_values[1] == 1 && arduino_values[2] == 0 && arduino_values[3] == 1) {
    volume = int(1000 * analysisPY.analyze());
    if (soundPY.isPlaying() == false) {
      soundPY.play();
    }
  } else {
    soundRY.pause();
  }
  if (arduino_values[0] == 0 && arduino_values[1] == 1 && arduino_values[2] == 0 && arduino_values[3] == 0) {
    volume = int(1000 * analysisP.analyze());
    if (soundP.isPlaying() == false) {
      soundP.play();
    }
  } else {
    soundP.pause();
  }
  if (arduino_values[0] == 0 && arduino_values[1] == 0 && arduino_values[2] == 1 && arduino_values[3] == 1) {
    volume = int(1000 * analysisRY.analyze());
    if (soundRY.isPlaying() == false) {
      soundRY.play();
    }
  } else {
    soundRY.pause();
  }
  if (arduino_values[0] == 0 && arduino_values[1] == 0 && arduino_values[2] == 1 && arduino_values[3] == 0) {
    volume = int(800 * analysisR.analyze());
    if (soundR.isPlaying() == false) {
      soundR.play();
    }
  } else {
    soundR.pause();
  }
  if (arduino_values[0] == 0 && arduino_values[1] == 0 && arduino_values[2] == 0 && arduino_values[3] == 1) {
    volume = int(900 * analysisY.analyze());
    if (soundY.isPlaying() == false) {
      soundY.play();
    }
  } else {
    soundY.pause();
  }



  //send the values to Arduino
  processing_values[0] = volume/2;

  sendSerialData();
  delay(20); 

  
/*
  float x_r = random(-600, 600);
  float y_r = random(-600, 600);
  float dia_r = random(300, 360);

  background(255, 50);
  noStroke();
  
  
  if (arduino_values[0] == 1) {
    gballs.add(new Ball(width/4 + x_r, height/4 + y_r, dia_r));
  }
  if (arduino_values[1] == 1) {   
    pballs.add(new Ball(3*width/4 + x_r, height/4 + y_r, dia_r));
  }
  if (arduino_values[2] == 1) {
    rballs.add(new Ball(width/4 + x_r, 3*height/4 + y_r, dia_r));
  }
  if (arduino_values[3] == 1) {
    yballs.add(new Ball(3*width/4 + x_r, 3*height/4 + y_r, dia_r));
  }

  for (int i = 0; i < gballs.size(); i++) {
    Ball b = gballs.get(i);
    b.move();
    b.gdisplay();
  }
  if (gballs.size() > 30) {
    gballs.remove(0);
  }
  for (int i = 0; i < pballs.size(); i++) {
    Ball b = pballs.get(i);
    b.move();
    b.pdisplay();
  }
  if (pballs.size() > 30) {
    pballs.remove(0);
  }
  for (int i = 0; i < rballs.size(); i++) {
    Ball b = rballs.get(i);
    b.move();
    b.rdisplay();
  }
  if (rballs.size() > 30) {
    rballs.remove(0);
  }
  for (int i = 0; i < yballs.size(); i++) {
    Ball b = yballs.get(i);
    b.move();
    b.ydisplay();
  }
  if (yballs.size() > 30) {
    yballs.remove(0);
  }
  
  text(frameRate, 10, 20);
}

class Ball {
  float x, y, dia, xSpd, ySpd;

  Ball(float _X, float _Y, float _dia) {
    x = _X;
    y = _Y;
    dia = _dia;
    xSpd = random(-19, 19);
    ySpd = random(-19, 19);
  }

  void move() {
    x += xSpd;
    y += ySpd;
  }

  void slowDown() {
    xSpd *= 0.94;
    ySpd *= 0.94;
  }

  void speedUp() {
    xSpd *= 1.02;
    ySpd *= 1.02;
  }

  void gdisplay() {
    pushMatrix();
    translate(x, y);
    int randomV = int(random(40));
    fill(77,196-randomV,75,50);
    circle(0, 0, dia);
    popMatrix();
  }
  
  void pdisplay() {
    pushMatrix();
    translate(x, y);
    int randomV = int(random(40));
    fill(203, 78, 255-randomV, 50);
    circle(0, 0, dia);
    popMatrix();
  }
  void rdisplay() {
    pushMatrix();
    translate(x, y);
    int randomV = int(random(40));
    fill(254-randomV,62,62,50);
    circle(0, 0, dia);
    popMatrix();
  }
  void ydisplay() {
    pushMatrix();
    translate(x, y);
    int randomV = int(random(40));
    fill(41,94,250-randomV,50);
    circle(0, 0, dia);
    popMatrix();
  }
  */
}



// the helper function below receives the values from arduino
// in the "arduino_values" array from a connected Arduino
// running the "serial_read_and_write_arduino" sketch
// (You won't need to change this code.)

void getSerialData() {
  while (serialPort.available() > 0) {
    String in = serialPort.readStringUntil( 10 ); // 10 = '\n'  Linefeed in ASCII
    if (in != null) {
      print("From Arduino: " + in);
      String[] serialInArray = split(trim(in), ",");
      if (serialInArray.length == NUM_OF_VALUES_FROM_ARDUINO) {
        for (int i=0; i<serialInArray.length; i++) {
          arduino_values[i] = int(serialInArray[i]);
        }
      }
    }
  }
}


// the helper function below sends the variables
// in the "processing_values" array to a connected Arduino
// running the "serial_read_and_write_arduino" sketch
// (You won't need to change this code.)

void sendSerialData() {
  String data = "";
  for (int i=0; i<processing_values.length; i++) {
    data += processing_values[i];
    // if i is less than the index number of the last element in the values array
    if (i < processing_values.length-1) {
      data += ",";  // add splitter character "," between each values element
    }
    // if it is the last element in the values array
    else {
      data += "\n";  // add the end of data character "n"
    }
  }

  // write to Arduino
  serialPort.write(data);
  print("To Arduino: " + data);  // this prints to the console the values going to Arduino
}

Leave a Reply

Your email address will not be published. Required fields are marked *