Final Project Proposal

For the purposes of the Final Project, in order to satisfy the requirements of an interactive system which requires systems of listening, thinking, and speaking from at least 2 parties, and should make use of Arduino and P5Js, we have preliminarily thought of developing an ‘Arcade Game’ console.

While the intricacies are not fine tuned yet, the initial idea is to develop an Extensive Game in p5Js, not a simple one, but an elaborate game with multiple levels which is very challenging. For this, we have though of a childhood favorite called ‘PacXon’ which is similar to PacMan but involves a relatively free space with area to capture. To have a sense of a similar game, we can look here (https://www.gamesbutler.com/game/29933/pacxon-deluxe/)

We believe creating this would require some algorithms, and extremely complex state machines with the utility of power-ups, and would develop our Object Oriented Programming skills in P5Js to an advanced level.

Moving forward, we would then develop a ‘JoyStick’ for this game, that would be designed for the purposes of this game. As an idea, the JoyStick would be a breadboard with multiple buttons for left, right, up, and down movements as well as a Potentiometer to control speeds, and a Piezo Buzzer to produce vibration like sounds on collisions for ‘Haptic Feedback’. We would also incorporate multiple LEDs and different notes of sounds with the state machines, realizing the mechanism to play the required tone at the appropriate time.

The idea is still in works and we are open to feedback!

The project is intended to be completed by Ishmal Khalid, Zunair Viqar, and Abraiz Azhar.

Assignment 8: In-class exercises

For the 11th Week assignment, we were tasked to pair up in groups of 2-3, and complete the following 3 exercises to fully understand the connection and communication methodologies between Arduino and p5Js. The 3 exercises were:

      1. make something that uses only one sensor  on arduino and makes the ellipse in p5 move on the horizontal axis, in the middle of the screen, and nothing on arduino is controlled by p5
      2. make something that controls the LED brightness from p5
      3. take the gravity wind example (https://editor.p5js.org/aaronsherwood/sketches/I7iQrNCul) and make it so every time the ball bounces one led lights up and then turns off, and you can control the wind from one analog sensor

The requirements were to post the code for each exercise, and the video of the LED lighting up with the ball bouncing.

We paired up in a group of 3, consisting of Abraiz Azhar, Ishmal Khalid, and Zunair Viqar. In the next few sections, we have described the solutions to each of the above exercises.

Prompt 1

Make something that uses only one sensor on arduino and makes the ellipse in p5 move on the horizontal axis, in the middle of the screen, and nothing on arduino is controlled by p5

Implementation

For this part, I made use of a potentiometer and connected it to the Arduino’s A0 port. The variable rVal changes according to the position of the potentiometer and this variable is in turn mapped to the ellipse’s x-position. I made the ellipse’s grey-scale value change according to the potentiometer’s reading.

Code
let rVal = 0;

function setup() {
  createCanvas(640, 480);
  textSize(18);
}

function draw() {
  // one value from Arduino controls the background's red color
  background(map(rVal, 0, 1023, 0, 255), 255, 255);

  if (!serialActive) {
    text("Press Space Bar to select Serial Port", 20, 30);
  } else {
    text("Connected", 20, 30);
    

    // Print the current values
    text('rVal = ' + str(rVal), 20, 50);
    text('alpha = ' + str(alpha), 20, 70);

  }
  
  // making an ellipse that moves according to the potentiometer's rVal 
  noStroke()
  fill(map(rVal, 0, 1023, 0, 255));
  ellipse(map(rVal, 0, 1023, 20, width - 20), height/2, 20);
}
Circuit

 

 

 

 

 

 

Prompt 2

Implementation & Challenges

The prompt for the second task seemed straightforward initially: create a system to control LED brightness using p5. However, it turned out to be more challenging than expected. Our initial approach was to map the mouseX position relative to the screen width to adjust the brightness of the lamp accordingly. We removed the code for reading from p5 and writing to Arduino, as we thought only sending data from p5 was needed. However, we later realized that both read and write operations are necessary for establishing a connection.

Despite this realization, we still encountered issues as we didn’t initially understand that data must be continuously read and written from both Arduino and p5 for the circuit to function properly. It wasn’t just limited to the handshake phase, but required continuous data exchange. Despite the challenges, this exercise provided us with a deeper understanding of the serial connection between p5 and Arduino.

We also faced challenges with data formatting during the data exchange. It was important to ensure that the data sent from p5 was properly formatted with the addition of ‘\n’, and that Arduino used println instead of print to receive the data. This was crucial for establishing reliable communication between p5 and Arduino, and it required careful attention to detail to get the formatting right.

Code
p5Js
let rVal = 0;
let alpha = 255;
let left = 0;
let right = 0;
let brightness = 0;

function setup() {
  createCanvas(640, 480);
  textSize(18);
}

function draw() {
  // one value from Arduino controls the background's red color
  background(map(rVal, 0, 1023, 0, 255), 255, 255);

  // the other value controls the text's transparency value
  brightness = map(mouseX, 0, 640, 0, 255);

  if (!serialActive) {
    text("Press Space Bar to select Serial Port", 20, 30);
  } else {
    text("Connected", 20, 30);
    

    // Print the current values
    text('rVal = ' + str(rVal), 20, 50);
    text('alpha = ' + str(alpha), 20, 70);

  }

}

function keyPressed() {
  if (key == " ") {
    // important to have in order to start the serial connection!!
    setUpSerial();
  }
}


function readSerial(data) {
  ////////////////////////////////////
  //READ FROM ARDUINO HERE
  ////////////////////////////////////

  if (data != null) {

    //////////////////////////////////
    //SEND TO ARDUINO HERE (handshake)
    //////////////////////////////////
    let sendToArduino = brightness + "\n";
    writeSerial(sendToArduino);
  }
}
Arduino .ino
int leftLedPin = 2;
int rightLedPin = 5;

void setup() {
  // Start serial communication so we can send data
  // over the USB connection to our p5js sketch
  Serial.begin(9600);

  // We'll use the builtin LED as a status output.
  // We can't use the serial monitor since the serial connection is
  // used to communicate to p5js and only one application on the computer
  // can use a serial port at once.
  pinMode(LED_BUILTIN, OUTPUT);

  // Outputs on these pins
  pinMode(leftLedPin, OUTPUT);
  pinMode(rightLedPin, OUTPUT);

  // Blink them so we can check the wiring
  digitalWrite(leftLedPin, HIGH);
  digitalWrite(rightLedPin, HIGH);
  delay(200);
  digitalWrite(leftLedPin, LOW);
  digitalWrite(rightLedPin, LOW);

  // start the handshake
  while (Serial.available() <= 0) {
    digitalWrite(LED_BUILTIN, HIGH); // on/blink while waiting for serial data
    Serial.println("0"); // send a starting message
    delay(300);            // wait 1/3 second
    digitalWrite(LED_BUILTIN, LOW);
    delay(50);
  }
}

void loop() {
  // wait for data from p5 before doing something
  while (Serial.available()) {
    digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data

    int right = Serial.parseInt();
    if (Serial.read() == '\n') {
      analogWrite(rightLedPin, right);
      int sensor = analogRead(A0);
      Serial.println(sensor);
    }
  }
  digitalWrite(LED_BUILTIN, LOW);
}

Prompt 3

Implementation & Challenges

For the very last prompt, we were required to take an input from Arduino in the form of an Analog Sensor and also send data to Arduino to blink an LED.

Using an existing p5Js Sketch (https://editor.p5js.org/aaronsherwood/sketches/I7iQrNCul), the requirement was to blink the LED when the ball bounces, and use an Analog Sensor to control the wind.

Therefore, making use of the circuit we designed in class by taking help from the basics of these 3 sources, we began to adapt the Gravity Wind Example from p5Js:

The first task was to detect a bounce, and once a bounce was detected, we just simply sent a signal of ‘1’ to the Arduino – which only meant switching on the light, which would then switch off with ‘0’ being sent when the ball was in motion.

Similarly, the Potentiometer value was read from the Arduino, and its value was sent to the P5Js sketch. This value was checked to be either greater then 512, or less than that, which then meant left or right movement of the wind.

Video
Code
p5Js
let velocity;
let gravity;
let position;
let acceleration;
let wind;
let drag = 0.99;
let mass = 50;

let rVal = 0;
let alpha = 255;
let left = 0;
let right = 0;

function setup() {
  createCanvas(640, 360);
  noFill();
  position = createVector(width/2, 0);
  velocity = createVector(0,0);
  acceleration = createVector(0,0);
  gravity = createVector(0, 0.5*mass);
  wind = createVector(0,0);
}

function draw() {
  left = 0;
  background(255);
  applyForce(wind);
  applyForce(gravity);
  velocity.add(acceleration);
  velocity.mult(drag);
  position.add(velocity);
  acceleration.mult(0);
  fill(0);
  ellipse(position.x,position.y,mass,mass);
  if (position.y > height-mass/2) {
      velocity.y *= -0.9;  // A little dampening when hitting the bottom
      position.y = height-mass/2;
    }
  
  
  if(abs(velocity.y)>1){
    if(position.y+(mass/2)>=(height)){
      left = 1;
    }
  }
  
  // print(alpha);
  
  if(alpha>512){
    // print("right");
    wind.x=1;
  }
  else{
    // print("left");
    wind.x=-1;
  }
  

}

function applyForce(force){
  // Newton's 2nd law: F = M * A
  // or A = F / M
  let f = p5.Vector.div(force, mass);
  acceleration.add(f);
}

function keyPressed(){
  if (key == " ") {
    // important to have in order to start the serial connection!!
    setUpSerial();
  }
  
  if (keyCode==UP_ARROW){
    // wind.x=-1;
    position.y = 200;
  }
  
  if (keyCode==ENTER){
    mass=random(15,80);
    position.y=-mass;
    velocity.mult(0);
  }
}


function readSerial(data) {
  ////////////////////////////////////
  //READ FROM ARDUINO HERE
  ////////////////////////////////////

  if (data != null) {
    // make sure there is actually a message
    alpha = data;

    //////////////////////////////////
    //SEND TO ARDUINO HERE (handshake)
    //////////////////////////////////
    let sendToArduino = left + "\n";
    writeSerial(sendToArduino);
  }
}
Arduino .ino
// Week 11.2 Example of bidirectional serial communication

// Inputs:
// - A0 - sensor connected as voltage divider (e.g. potentiometer or light sensor)
// - A1 - sensor connected as voltage divider 
//
// Outputs:
// - 2 - LED
// - 5 - LED

int leftLedPin = 2;

void setup() {
  // Start serial communication so we can send data
  // over the USB connection to our p5js sketch
  Serial.begin(9600);

  // We'll use the builtin LED as a status output.
  // We can't use the serial monitor since the serial connection is
  // used to communicate to p5js and only one application on the computer
  // can use a serial port at once.
  pinMode(LED_BUILTIN, OUTPUT);

  // Outputs on these pins
  pinMode(leftLedPin, OUTPUT);

  // Blink them so we can check the wiring
  digitalWrite(leftLedPin, HIGH);
  delay(200);
  digitalWrite(leftLedPin, LOW);



  // start the handshake
  while (Serial.available() <= 0) {
    digitalWrite(LED_BUILTIN, HIGH); // on/blink while waiting for serial data
    Serial.println("0,0"); // send a starting message
    delay(300);            // wait 1/3 second
    digitalWrite(LED_BUILTIN, LOW);
    delay(50);
  }
}

void loop() {
  // wait for data from p5 before doing something
  while (Serial.available()) {
    digitalWrite(LED_BUILTIN, HIGH); // led on while receiving data

    int left = Serial.parseInt();
    // int right = Serial.parseInt();
    if (Serial.read() == '\n') {
      digitalWrite(leftLedPin, left); // Write value to the bulb, to blink it
      int sensor2 = analogRead(A1); // Read input from the Potentiometer
      delay(5);
      Serial.println(sensor2); // Send message to p5js
    }
  }
  digitalWrite(LED_BUILTIN, LOW);
}
Circuit

 

Week 11 – In-class Exercises (moving ellipse, LED brightness, Gravity wind example)

Group mates: Swostik Pati and Irem Naz Celen

Task 1:

make something that uses only one sensor on arduino and makes the ellipse in p5 move on the horizontal axis, in the middle of the screen, and nothing on arduino is controlled by p5

The code provided in the lecture notes for both Arduino and P5.js was used as-is, except for the draw function in P5.js. We modified the code to make the ellipse’s horizontal location change when the potentiometer was turned, and the vertical location change when the LDR input was changed. To prevent multiple visual responses from P5.js when the potentiometer and LDR were manipulated, we removed the background and fill functions.

Code:

Arduino Code

p5.js code

Video:

 

Task 2:

make something that controls the LED brightness from p5

We made some changes to both the Arduino and P5.js code for this task. To adjust the brightness of the LED, we utilized the keyboard’s Up and Down arrows as the input for the P5.js code. This changing value was then sent to the LED connected to PWM pin 5. We used analog write to this pin, which increased or decreased the LED value. If the value exceeded 255, it reset to 0 and vice versa.

Code:

Arduino Code

p5.js code

Video:

Task 3:

take the gravity wind example and make it so every time the ball bounces one led lights up and then turns off, and you can control the wind from one analog sensor

To complete the exercise, we made changes only to the P5.js code by incorporating the gravity wind example. The original Arduino code from the lecture notes remained unchanged. We divided the range of the potentiometer into three intervals, which set the wind vector to -1, 0, and 1 depending on its direction. These values are acceptable for the wind. We also implemented a collision detection flag. When a collision occurs, the LED on pin 2 is turned on. Whenever there is no collision, the LED is turned off.

Code:

Arduino Code

p5.js code

Video:

HW 8: 3 in-class exercises

Group mates: Swostik Pati and Aibar Talip
The Arduino circuit is kept the same as it was directed in the Lecture Notes.

Exercise 1 – Code & Video

The Arduino Code and the P5.Js code were directly used as given in the lecture notes, except for the draw function of p5.js. We amended the code so that turning the potentiometer would change the horizontal location of the ellipse. On the other hand, the LDR input would amend the vertical location of the ellipse. We also omitted the background and fill functions in order to not have multiple responses from the p5js visually for the actions observed on the potentiometer and the LDR.

The new draw function used in the p5.js code is shown below:

function draw() {
  background(0);
  fill(255);
  
  ellipse(map(alpha, 0, 1023, 0, width),map(rVal, 0, 1023, 0, height),40,60);
 
  // one value from Arduino controls the background's red color
  //background(map(rVal, 0, 1023, 0, 255), 255, 255);

  // the other value controls the text's transparency value
  //fill(255, 0, 255, map(alpha, 0, 1023, 0, 255));

  if (!serialActive) {
    text("Press Space Bar to select Serial Port", 20, 30);
  } else {
    text("Connected", 20, 30);
    // Print the current values
    text('rVal = ' + str(rVal), 20, 50);
    text('alpha = ' + str(alpha), 20, 70);
  }
}

Exercise 2 – Code & Video

For this exercise we amended the Arduino code a little as well as the p5.js code. In order to control the LED brightness, we used the keyboard, Up and Down arrows, as the input for the p5.js code that was running and then send this changing value to the LED that was connected in PMW pin 5. We analog wrote to this pin, by the incrementing/decrementing value of the LED, which resets 0 if it passes 255, and vice versa.

The new draw function and the keyPressed() function is as follows:

function draw() {
  background(255, 255, upVal,upVal);

  if(upVal==255) upVal =0;
  if(upVal==0) upVal=255;

  if (!serialActive) {
    text("Press Space Bar to select Serial Port", 20, 30);
  } else {
    text("Connected", 20, 30);
  }
}


function keyPressed() {
  if (keyCode == UP_ARROW) {
    upVal += 10;
  }
  if (keyCode == DOWN_ARROW) {
    upVal -= 10;
  }
  if (key == " ") {
    // important to have in order to start the serial connection!!
    setUpSerial();
  }
}

 

The following change is made to the p5.js code in the definition of the values that are sent to the Arduino, as the information for the LED at pin 5 is not digital but analog now, while the pin 2 LED is set to 0 indefinitely.

//////////////////////////////////
      //SEND TO ARDUINO HERE (handshake)
      //////////////////////////////////
      let sendToArduino = upVal + "," + 0 + "\n";
      writeSerial(sendToArduino);

Amendments to the Arduino code are as follows, in the section where the LED values are set:

// inside loop function of arduino
void loop{
.....
    int right = Serial.parseInt();
    int left = Serial.parseInt();
    if (Serial.read() == '\n') {
      digitalWrite(leftLedPin, left);
      analogWrite(rightLedPin, right);
...}

 

Exercise 3 – Code & Video

Only the p5.js code from the lecture notes is amended for the exercise after being combined with the gravity wind example given while the original Arduino code from the lecture notes is used. The range of the potentiometer is divided into 3 intervals, which accordingly sets the wind vector as -1, 0, and 1, as these are the acceptable values for the wind according to its direction. A flag for checking a collision has happened is put in place, in which ever case it is true the LED on pin 2 is turned on, and everytime it is “not collided” the LED is turned down.

The final version of the p5.js code used is as follows:

let bFlag = true;
let velocity;
let gravity;
let position;
let acceleration;
let wind;
let drag = 0.99;
let mass = 50;

let rVal = 0;
let upVal = 0;
let alpha = 255;
let left = 0;
let right = 0;

function setup() {
  createCanvas(640, 360);
  noFill();
  position = createVector(width / 2, 0);
  velocity = createVector(0, 0);
  acceleration = createVector(0, 0);
  gravity = createVector(0, 0.5 * mass);
  wind = createVector(0, 0);
}

function draw() {
  background(255);
  applyForce(wind);
  applyForce(gravity);
  velocity.add(acceleration);
  velocity.mult(drag);
  position.add(velocity);
  acceleration.mult(0);
  ellipse(position.x, position.y, mass, mass);
  if (position.y > height - mass / 2) {
    velocity.y *= -0.9; // A little dampening when hitting the bottom
    position.y = height - mass / 2;
    if(bFlag){
      print("collided");
      bFlag=false;
      left = 1;
    }
    else
      left=0;
  }
  else{
    bFlag=true;
    left=0;
  }

  // one value from Arduino controls the background's red color
  //background(map(rVal, 0, 1023, 0, 255), 255, 255);

  // the other value controls the text's transparency value
  //fill(255, 0, 255, map(alpha, 0, 1023, 0, 255));

  if (!serialActive) {
    text("Press Space Bar to select Serial Port", 20, 30);
  } else {
    text("Connected", 20, 30);

    // Print the current values
    //text("rVal = " + str(rVal), 20, 50);
    //text("alpha = " + str(alpha), 20, 70);
  }
//wind.x = map(alpha, 0, 1023, 0, 255);
  if(alpha>670)
    wind.x=1;
  else if(alpha>320)
    wind.x=0;
  else
    wind.x=-1;
  print(wind.x);
 
  // click on one side of the screen, one LED will light up
  // click on the other side, the other LED will light up
}
function keyPressed() {
  if (key == " ") {
    // important to have in order to start the serial connection!!
    setUpSerial();
  }
  if(keyCode==UP_ARROW){
    position = createVector(width / 2, 0);
  }
  if (key == " ") {
    mass = random(15, 80);
    position.y = -mass;
    velocity.mult(0);
  }
}

// This function will be called by the web-serial library
// with each new *line* of data. The serial library reads
// the data until the newline and then gives it to us through
// this callback function
function readSerial(data) {
  ////////////////////////////////////
  //READ FROM ARDUINO HERE
  ////////////////////////////////////

  if (data != null) {
    // make sure there is actually a message
    // split the message
    let fromArduino = split(trim(data), ",");
    // if the right length, then proceed
    if (fromArduino.length == 2) {
      // only store values here
      // do everything with those values in the main draw loop
      rVal = fromArduino[0];
      alpha = fromArduino[1];
    }

    //////////////////////////////////
    //SEND TO ARDUINO HERE (handshake)
    //////////////////////////////////
    let sendToArduino = left + "," + right + "\n";
    writeSerial(sendToArduino);
  }
}

function applyForce(force) {
  // Newton's 2nd law: F = M * A
  // or A = F / M
  let f = p5.Vector.div(force, mass);
  acceleration.add(f);
}

Reflections

These exercises were very enjoyable and definitely interesting to try as they allowed us to grasp the communication between the p5.js and Arduino way better. We were able to get exercises in for this complex relationship before devising our plan for the final project.

Final Project Idea – Collision and Edge Detection Robot with Arduino and p5.js

Concept

The aim of this project is to create a robot that can avoid collisions and sudden edges while moving around. The robot will be controlled using an Arduino board and p5.js, a JavaScript library for creative coding. The robot will be equipped with an ultrasonic distance sensor and an infrared sensor to detect collisions and edges respectively. The robot will have two different modes of operation which can be controlled using serial communication between the Arduino and p5.js. One mode will allow the robot to roam freely, while the other mode will allow the user to control the robot using keys on the computer. The movement of the robot will be mapped onto the p5.js canvas.

Implementation

One of the Arduino boards will be connected to the computer which receives serial information from p5 and transmits them over to the other Arduino board. This is a two way link communication between the robot and the computer. The ultrasonic distance sensor will be connected to the servo motor, which will rotate the sensor to scan the environment. The infrared sensor will be attached to the front of the robot chassis to detect edges. The robot moves around using regular motors and wheels. Whenever an edge is detected or the distance sensor senses a possible collision, it starts moving backward in order to avoid imminent danger. It also transmits back the movement data that is later displayed in the form of a path in the p5 canvas.

Final Project Preliminary Concept – Togyzkumalak

CONCEPT

For our final project, I want to create a version of the Kazakh traditional board game, Togyzkumalak (transl. “nine pebbles”). The game is played on a board consisting of two rows of nine pits each, with 2 larger pits (storehouses) between the two rows. The objective of the game is to capture more pebbles than the opponent (-> high score). This is a two-player game.

game setup for reference

Each player will be using three buttons connected through Arduino to p5 to control their movements in the game (left, right, enter). On p5 will be the visualization of the board. Players will use buttons to choose which pit to take the pebbles from.

The rules of the game are (with consideration of Arduino):

1) The game begins with 9 pebbles in each pit. Each player will be given 1 minute to make a move.

2) The first player chooses one of the 9 pits on their side using the “left”, “right”, and “enter” buttons on their Arduino.

3) All of the pebbles from the chosen pit are distributed evenly over the pits in an anti-clockwise direction.

        • If there is more than 1 pebble in the pit, the first pebble is put back into the pit it was taken from.
        • If there is only 1 pebble in the pit, the first pebble is moved to the next pit in the anti-clockwise direction.
anti-clockwise movement of the pebbles

4) If the last pebble to be moved is put into one of the opponent’s pits and the total of the pebbles in that pit is an even number, they get moved to the player’s storehouse and add to their total score.

moving pebbles from the opponent’s pit if the total in the said pit is an even number

5) opponent’s pit can be “conquered”, meaning that all the pebbles that ever fall on that pit will move to the player’s storehouse. However, there are some more conditions that need to be followed to do that (it will be checked by p5 automatically):

        • the total of the pebbles in the last pit you’ve visited must be 3;
        • the pit shouldn’t be the rightmost pit of the player (pit #9);
        • you must not already have a “conquered” pit;
        • if your opponent already has “conquered” a pit on your side, you can’t “conquer” a pit that is opposite to it;

6) If one of the players doesn’t have any more pebbles in any of their 9 pits, the opponent’s pits are emptied into their storehouse.

7) The one with the biggest score wins.

CREATIVITY

To add something new to the game, chance games will be played between the turns:

        • after every 3rd turn, a player will be given a chance to roll a die in the game. The die will have both negative ((-3) to (-1)) and positive numbers (1 to 3). The number shown will be added to the score of the player.
        • after every 7th turn, a player will be given a choice between three cards shown backward. One of the cards will be empty, one will have a challenge, and the last one will have a bonus. Drawing an empty card will safely return you to the game. Drawing a challenge card will make decrease your turn time to 30s for the next two turns. Drawing a bonus card will add 1 more minute to your turn time for the next two turns.

POSSIBLE CHALLENGES

I think I will have a difficult time implementing the game logic. Another thing I usually have issues with is checking the time (setting up a timer). I also need to think of the way the transitions between different states of the game to make it look animated and not mechanical.

Are You Stressed? (Final Project Preliminary Concept)

Concept:

For my final project, I want to create an interactive tool that helps to visualize stress levels during finals seasons. It will allow college students to relieve stress through squeezing and screaming and produce a unique visual mapping of their stress. The tool will incorporate a microphone in a cup and either a force-sensitive resistor or an air pressure sensor inside a squeezable object (a plushie or a stress ball). The pressure and sound inputs will be used to determine stress levels based on duration and intensity, and the results will be displayed on a screen. Us

Implementation:

My tool will consist of 2 parts: the hardware (arduino) and the software (p5js).

Arduino will receive the input, keep track of the duration and intensity of each input: sound, and touch, and send that data to p5js. I might also add a switch to start the process and to make the timing easier. I expect arduino to finish processing the data and then send it to p5js to visualize.

P5js will get the input from arduino, map the intensity and duration to stress levels in terms of colors and size of color dots and print the output on the screen (an output similar to the one below).

In the end, it would be great if the users can download/print out their stress profile but I am not sure yet how feasible that is.

Challenges

I anticipate building an aesthetically pleasing and functional tool that can be squeezed hard yet still work will be the biggest challenge. I am thinking of using either a plushie or a stress ball for that but at the same time trying to see if I can get hold of an air pressure sensor so I can use a balloon.

Premium Vector | Abstract vector background with pink and blue spots with blur effect

Arduino + P5JS

Exercise 1

Link to the code

Moving ellipse with a potentiometer.

Exercise 2

Link to the code

Using the mouse location on the horizontal axis to change the LED brightness.

Exercise #3

Link to the code

Lighting up the LED when the ball touches the ground, controlling the horizontal direction of the ball using a potentiometer, and creating a new ball when the potentiometer reads 0.

 

HW8: In-class Exercises (moving ellipse, LED brightness, gravity wind example…)

EXERCISE 1

Task description: Make something that uses only one sensor on Arduino and makes the ellipse in p5 move on the horizontal axis, in the middle of the screen, and nothing on Arduino is controlled by p5.

schematic used
setup used for all three exercises

Here is the link to the p5 code with the Arduino code commented out at the end of it.

If the video window doesn’t show, use this link to see the demo.

EXERCISE 2

Task description: Make something that controls the LED brightness from p5.

Here is the link to the p5 code with the Arduino code commented out at the end of it.

If the video window doesn’t show, use this link to see the demo.

EXERCISE 3

Task description: Take the gravity wind example and make it so that every time the ball bounces one led lights up and then turns off, and you can control the wind from one analog sensor.

Here is the link to the p5 code with the Arduino code commented out at the end of it.

If the video window doesn’t show, use this link to see the demo.