In Class Exercises by Linh and Sihyun

Exercise 1:

Link to the video: https://youtube.com/shorts/4ek33gKQaNY?si=3ArQyArCtsPfHlGx

P5 sketch: 

p5.js Code:

let xposition = 100;
function setup() {
  createCanvas(640, 480);
  textSize(18);
}
function draw() {
  background(0, 255, 0);
  fill(0);
  ellipse(xposition, height / 2, 50, 50);
}

function keyPressed() {
  if (key == " ") {
    // Calls a function to set up the serial connection
    setUpSerial();
  }
}

// Function to read data from the serial port
function readSerial(data) {
  // Check if data received is not null
  if (data != null) {
    // Maps the integer value of data from range 0-1023 to 0-640 and updates xposition
    xposition = map(int(data), 0, 1023, 0, 640);
  }
}

Arduino Code:

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

void loop() {


      int sensor = analogRead(A0);
      delay(5);
      Serial.println(sensor);
  
}

Circuit: 

For this exercise, we have utilized the potentiometer to change the position of the ellipse in the p5.js sketch. As shown in the code snippet, the ellipse’s x position is mapped to the value of the potentiometer from the Arduino. First of all, by calling the setUpSerial() function when the space bar is pressed, the p5.js sets up the serial connection with the Arduino. Then, using the readSerial(data) the p5.js reads data regarding the potentiometer value from the Arduino. 

For the Arduino, we used Serial. begin(9600) to start the serial communication. Inside the loop function, we have Serial.println(sensor) to send the sensor value to the serial port as a line of text (string), ending in a newline character.

Exercise 2: 

Video:

 P5 sketch: 

P5.js code

In the p5 code, the mouseX is used to control the brightness of the LED light. MouseX is mapped from 0 to width of the canvas to 0 to 255. Utilizing the function readSerial(), we send the value of the mapped mouseX to the Arduino using the below line of codes:

function readSerial(data) {

  if (data != null) {
    //////////////////////////////////
    //SEND TO ARDUINO HERE (handshake)
    //////////////////////////////////
    let sendToArduino = left + "\n";
    writeSerial(sendToArduino);
  }
}

Arduino Code

In the Arduino code, after the initial handshake, the code continuously checks for any data that is sent from the Arduino code. It then parses the sending string and uses that string to control the brightness of the LED using analogWrite. The value has been mapped to the range of 255 so there is no need of mapping again in the Arduino code.

int leftLedPin = 3;


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') {
      analogWrite(leftLedPin, left);
      Serial.println();
    }
  }
  digitalWrite(LED_BUILTIN, LOW);
}

Circuit

Exercise 3

Video:

P5.js Sketch

For the LED to light up every bounce, we assigned a flag “ground”. Everytime the ball hits the ground, we set ground = true else it equals to false.

if (position.y > height-mass/2) {
    velocity.y *= -0.9;  // A little dampening when hitting the bottom
    position.y = height-mass/2;
  ground = true;
  }
else{
  ground = false;
}

If ground = true, we will send to arduino the value of 1, else, we will send 0. We did this because we only use digitalWrite in Arduino which only accepts LOW (0) and HIGH (1) as its value.

if (ground) {
     sendToArduino = "1"+"\n";
    }
    else{
       sendToArduino = "0"+"\n";
    }

For the control of the wind, we used the potentiometer to change the value of the wind. Since there is only one data coming from the Arduino, we didn’t use the trim to parse the function. Instead, we directly map the receiving data to the wind value:

wind.x= map(int(data), 0,1023,-1, 1);

Arduino Code: 

int ledPin = 8;


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(ledPin, OUTPUT);


 // Blink them so we can check the wiring
 digitalWrite(ledPin, HIGH);
 delay(200);
 digitalWrite(ledPin, 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 led = Serial.parseInt();
   if (Serial.read() == '\n') {
     digitalWrite(ledPin, led);
     int sensor = analogRead(A5);
     Serial.println(sensor);
   }
 }
 digitalWrite(LED_BUILTIN, LOW);
}

In the Arduino sketch, we initiated serial communication with Serial.begin(9600) within the setup() function to set up data transfer at 9600 bits per second. The ledPin variable is set to 8, corresponding to the pin connected to an LED. We use Serial.available() to check for incoming serial data. Initially, the sketch blinks the LED on pin 8 to verify the correct wiring. When it begins receiving data from the serial port, the built-in LED lights up as a signal of data processing. The received data is then used to control the state or brightness of the LED on pin 8. Additionally, the sketch reads the analog value from pin A5 (connected to a potentiometer) and sends this value back to the p5.js, facilitating a continuous, dynamic interaction between the Arduino hardware and the p5.js.

Circuit:

Reflection:

Initially, we had a bit of a problem understanding how the communication between the p5.js and Arduino works. After spending quite a few investigating the sample code, we identified a few of the differences we had in our code and the sample code that caused our code to not work. We also learnt the mapping of values between the p5.js values and the Arduino values (including both variable resistors and analogWrite ranges).

Final Project: Sizzling Steak

Concept

As a child, I played lots of Nintendo games. And one of my favorite games among various Nintendo games was Cooking Mama. Cooking Mama is a game that consists of cookery simulation-styled minigames. By successfully accomplishing each stage of the minigame, the user ends up making a nice-looking cuisine.  Inspired by this game, I would like to create a game called “Sizzling Steak” where the user cooks a steak through three stages. The three stages that consist this game are the following: 

Buying ingredients from the Supermarket: 

In this stage, there would be obstacles and ingredients coming towards the user. By jumping using the button switch, the user should avoid the obstacles and collect the necessary ingredients. Once the user was able to collect 10 necessary ingredients, the stage will successfully end and move to the next stage. However, if the user was not able to successfully avoid the obstacles, the user would have to restart the stage. 

Putting the steak on the grill and cooking it:

In this stage, the user can control the fire intensity using the potentiometer. According to the fire intensity that the user chose, the flip time may be faster or slower. Once it is time to flip, the p5.js will send a signal to the arduino and it will lit up a LED light.  The user would have to flip the steak using the button switch. Here, the user has to flip as fast as she/he can. If the user pressed the button too late, the game would end. The user has to flip around 3-5 times perfectly to successfully end the stage and move to the next stage.

Putting the sauce on the steak: 

In the final stage, the user should squeeze the right amount of sauce on the steak. Here, a flex sensor will be utilized to measure the amount of sauce. The flex sensor will be inserted into a plastic sauce bottle. So, the user will have to squeeze the sauce bottle to play this game. If the user squeezes the bottle too much, there will be too much sauce placed and the user will fail the mission. The goal of this game is to squeeze the bottle with the right pressure and have the right amount of sauce. 

Inspirational images from Cooking Mama: 

Progress so far

So far, I have worked on the game logic of each stage of the game in three separate p5.js sketches. I didn’t put the game-ending conditions yet. 

Here are the links to the sketches: 

Stage 1: https://editor.p5js.org/sihyunkim/sketches/bPDuewgm1

Stage 2: https://editor.p5js.org/sihyunkim/sketches/SPUVViPV3

Stage 3: https://editor.p5js.org/sihyunkim/sketches/wsIpZQBAA

 

Week 12 Assignment – Exercises done in class by Marcos Hernández and Marwan AbdElhameed

Introduction

During class, we were asked to complete, in pairs, three exercises in order to get more familiar with the serial communication between Arduino and p5.js. The exercises asked the following:

EXERCISE 01: ARDUINO TO P5 COMMUNICATION

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.

EXERCISE 02: P5 TO ARDUINO COMMUNICATION

Make something that controls the LED brightness from p5.

EXERCISE 03: BI-DIRECTIONAL COMMUNICATION

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

Therefore, in order to complete the assignment effectively, we split it respectively, and we communicated along the execution, since we needed to make sure we were not only following instructions adequately, but that we could finish on time.

Exercise #1 and #2  –  Marcos Hernández

For this assignment, there was not any tweaking of the code done in the file provided (W11_01_Bidirectional_Com.ino) alongside the class presentation in Week 12.

So, for the set-up, I just prepared the Arduino in a way that it functions with the code without being modified, since it already did everything needed for these two exercises. Although, in p5.js, I duplicated the example that we were provided on class to work with. Likewise, I did make changes since it would not replicate what was needed for exercise #1 and #2.

After setting up the Arduino, we have the following:

And with this code in p5.js that is modified so as every time the circle is clicked, the red LED gets turn on as well as having the possibility of moving it horizontally with a potentiometer via analog values:

let rVal = 0;
let alpha = 255;
let left = 0; // True (1) if mouse is being clicked on left side of screen
let right = 0; // True (1) if mouse is being clicked on right side of screen

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

function draw() {
  // one value from Arduino controls the background's red color
  background(255)

  // the other value controls the text's transparency value
  fill(255, 0,0)

  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);
  }

  // click on one side of the screen, one LED will light up
  // click on the other side, the other LED will light up
  if (mouseIsPressed) {
    if (mouseX > rVal-50 && mouseX < rVal+50 && mouseY > height/2-50 && mouseY < height/2+50) {
      right = 1;
    } 
  } else {
    right = 0;
  }
  ellipse(rVal, height/2, 50,50)
}

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

// 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
      
      // We take the string we get from Arduino and explicitly
      // convert it to a number by using int()
      // e.g. "103" becomes 103
      rVal = int(fromArduino[0]);
      alpha = int(fromArduino[1]);
    }

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

We have the following result observed in the video:

After completing these exercises, I started to feel more confident as to how I will work on my final project.

Exercise #3  –  Marwan AbdElhameed

This one is particular was challenging. Basically, the sensor data is sent to Arduino after mapping it to -1,1, then the Y position of the ball is sent to the Arduino and checked if it was >330. If it is, the LED at is switched to HIGH.

The code found in p5.js:

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

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() {
    if (!serialActive) {
    text("Press s 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);
  }
  
  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;
    }
}

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 (keyCode==LEFT_ARROW){
    wind.x=-1;
  }
  if (keyCode==RIGHT_ARROW){
    wind.x=1;
  }
  if (key==' '){
    mass=random(15,80);
    position.y=-mass;
    velocity.mult(0);
  }
   if (key == 's') {
    // important to have in order to start the serial connection!!
    setUpSerial();
  }
}

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 == 1) {
      
      wind = int(fromArduino[0]);
    }

    //////////////////////////////////
    //SEND TO ARDUINO HERE (handshake)
    //////////////////////////////////
    let sendToArduino = position.y + "\n";
    writeSerial(sendToArduino);
  }
}

The code sent to the Arduino:

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();
    if(left>=330){
       digitalWrite(leftLedPin, HIGH);
}
  
    if (Serial.read() == '\n') {
      digitalWrite(leftLedPin, left);
      int sensor = analogRead(A0);
      sensor = map(sensor,0,1023,-1,1);
      Serial.println(sensor);

    }
  }
  digitalWrite(leftLedPin, LOW);
}

After sending the setting up the Arduino, sending the code and using the one that was written in p5.js, we have the following result:

Conclusion

Working on Arduino, at first sight, might appear scary and too technical. But with these exercises, both my teammate and I feel more comfortable with the Arduino world. As they say, the hardest step will always be the first, and the rest, should be left to curiousness.

 

Week 12 Reading Response by Sihyun Kim

Reading the article reminded me of the time when I broke my arm. As a child, I broke my arm after jumping off my cousin’s bed and ended up with a pink cast on my arm. I hated the fact that I had a pink cast because it drew pity from people, which made me uncomfortable. I did my best to hide it by wearing a jacket wherever I went. 

The author of the article points out that ‘the priority for design for disability has traditionally been to enable while attracting as little attention as possible,’ and it was about trying not to project the image of ‘disability’ after all. Interestingly, the article uses eyeglasses as an example of how perceptions can shift. Once a plain and purely functional aid for a disability, eyeglasses have evolved into a fashion statement, celebrated for their aesthetic value and the personal style they add.

According to the article, the eyeglasses were also once functional aid for a disability that tried to “camouflage” the disability by making the eyeglasses “invisible pink plastic glasses”.  Now, we do not think at all that a person has poor eyesight or visional problems just because they wore glasses. This is because eyeglasses also serve as a fashion statement. Reading this article, I realized that “fashion” and “disability” are not two separate concepts that could never be integrated. 

I thought that this shift in how eyeglasses are perceived and other examples in the article showcase the importance of projecting a positive image rather than trying not to project an image at all. And this made me think that this could transform aids from something that people feel they need to hide, as I did with my pink cast, to something they want to showcase.

Reflecting further on this concept, I realized that it is the mindset surrounding disability that often defines it. By adopting an approach that values visibility and style, I believe that we can challenge and change the stigmatizing attitudes that suggest disabilities should be concealed. We can shift from a mindset that views disabilities as deficits to one that recognizes them as a part of human diversity to be accepted and embraced.

 

Reading Reflection – Week 10

Reflecting on the concepts mentioned in “Physical Computing’s Greatest Hits (and Misses),” it is clear that some project ideas appear frequently in physical computing. The different topics provide unique learning opportunities of physical interaction. makes you see the charm in revisiting old project ideas. It’s cool to think about how each student puts their spin on classic assignments like making digital instruments or smart clothing. This whole process teaches us a lot about how we interact with the tech we build, which is super handy for learning and creativity. It makes you see the charm in revisiting old project ideas. It’s interesting to think about how each student puts their own twist or spin on classic assignments like making digital instruments or wearable devices. This whole process teaches us a lot about how we interact with the tech we build, which is extremely useful for learning and creativity.

The second article, “A Public Physical Computing Service,” discusses the integration of physical computing in public spaces. By making technologies like Arduino and Raspberry Pi accessible to a broader audience, everyone gets a chance to play around and learn something new. This showcases the importance of community in technology education, and how shared resources and collaborative spaces can empower people and enhance collective creativity in the physical computing field.

Production Assignment – Week 10

For this assignment, we were tasked with using one digital sensor (on/off) and one analog sensor (variable) to control an LED each.

I used a potentiometer as my analog sensor to control and dim a blue LED based on the reading, and used a regular button as my digital sensor (switch).

I used arduino to get the readings from the potentiometer and control the blue LED, but for the switch and green LED, I just used the 5V out to keep things simple.

Materials Used:

  • Jumper Wires
  • Blue LED
  • Green LED
  • Resistor
  • Potentiometer
  • Button

Code:

const int ledPin = 10;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int sensorLevel = analogRead(A0); // Read from potentiometer
  int brightness = map(sensorLevel, 0, 1023, 0, 255); // Map sensor reading to LED brightness

  analogWrite(ledPin, brightness); // Control LED

  delay(100);
}

 

Demo:

Production Assignment – Week 9

For this assignment, we were tasked to create an unusual  switch without using our hands. I decided to create a pressure switch that can be stepped on to activate the LED.

I recycled some cardboard packaging I found to use as the casing, two sugar packets to create the spacing, two aluminum foil pads, some jumper wires, and an LED.

Demo:

Reflection:

Overall this was a fun project to work on, I could make it more durable to prevent it from falling apart.

Reading Reflection – Week 8

Reflecting on the insights from Don Norman’s essay, I find his integration of aesthetics and usability particularly thought-provoking. Attractive products aren’t merely pleasing to the eye but also functionally better due to the positive effect they provide. It’s enlightening to see the psychological and emotional layers behind product interactions; that our reactions to design are not just superficial but come from our cognitive and emotional thinking.

Norman also makes you wonder if there’s a relationship between functionality and aesthetic design, where they complement each other. This idea is not only innovative but also inspiring for anyone involved in creative design, prompting us to consider how the objects we create affect the emotional and cognitive experiences of users.

Week 12 Reading Response: Design Meets Disability

This reading by Graham Pullin was quite interesting. I especially loved how Pullin set up the contrast between the medical model of disability (which focuses on symptoms and the ability/inability to perform certain tasks) and the social model of disability (which views disabilities arising from social barriers that make spaces and conversations inaccessible to people with impairments), and how using fashion for assistive devices addresses the social model. There is a major focus by Pullin to break down the long-held misconception that form does not matter for assistive devices as long as they are capable of performing their specified function in a discrete manner. The goal so far when crafting these devices is to hide them, which only perpetuates the wrong belief that having a disability is shameful.

In that regard, I liked the comparison Pullin drew to eyeglasses. Eyeglasses are technically assistive devices too, and in many cases essential to prevent a disability. Under the medical model, myopia with a power more than -2.5D would pretty much be a disability, as without the help of glasses, people with high myopia are unable to see the world normally. However, glasses, and the fact that glasses are socially acceptable, assist in mitigating the impairment and prevent it from being a disability, pointing to the influence of the social model. Thus, as Pullin points out, there’s an urgent need to reconcile other assistive devices with social acceptability. For that, assistive devices need to be optimized for nor just function but also for form and aesthetic design.

My final point was that while Pullin is making a revolutionary call to include fashion designers and artists into the designing process, there’s one group that he has forgotten. One that is already underrepresented in the assistive device design process: people with disabilities themselves. To make a successful assistive device that has a preferable design, people with disabilities need to be involved at every step, not just as customers.

Final Project Progress | GyroMaze

For my final project, I have locked in on the idea of using a gyroscope device to control a ball inside a maze. Since then, I’ve successfully booked the equipment I need from Arts Booking and made considerable progress for my project.

~~The Maze~~

I utilized the p5 play library to help me build the game managers. I loaded two sprites: a cube and a black tile. The cube acts as the player, whereas the tile serves as the wall for the maze. These can be changed at any time.

let map = 
    [
    "@@@@@@@@@",
    "@   @   @",
    "@@@ @ @ @",
    "@@@   @ @",
    "@@@@@   @",
    "@@@@@@@@@",
    ];

new Tiles(map, 0.5, 0.5, 1, 1); //Those are the coordinates so that they start a bit right and not super too the edge of the windowWidth & windowHeight

 

Within the short period between the previous class, I was able to fully build the maze system complete with a character controller. The Tiles() function can read any list consisting of strings. Those strings are made out of @ and ‘SPACES’ to mark walls and empty space. Next, I made a separate list called map that has the layout of the whole maze. Hence, with this system, I can create as many mazes as I need to and easily implement a map randomizer for the final product.

if (kb.pressed('up') && isOpen(avatar.x, avatar.y-1)) {
    //SMOOTH MOVEMENT USING VECTOR
    avatar.moveTo(createVector(avatar.x, avatar.y-1), .1)
    
    //avatar.y--;

The character moves by a simple UP, DOWN, LEFT, RIGHT checking alongside isOpen() function. The function checks whether there is a ‘SPACE’ within the map. If there is, it returns true, which means the player can walk through it. If not, then there is a wall and the player cannot move through it.

~~The Physical Controller~~

The module that I booked from Equipments Center is a generic GY-85 sensor that comes with three features: an accelerometer, gyroscope, and magnetometer.

Help, it’s broken! (nope) Continue reading “Final Project Progress | GyroMaze”