Pillow Best Friends-Chengan Bai-Andy

 

B. CONCEPTION AND DESIGN:

I have found in the mid-term project that people in big cities are prone to depression, so we hope to make a pillow to help people sleep. We hope to make this pillow to interact with users, so that users can reduce anxiety and sleep better. We designed a character to represent the pillow on the computer and give feedback to the user. Users can choose songs to make the pillow sing to help them sleep. If the user is very anxious, he can hit a pillow to relieve the pressure, and the character on the computer will comfort the user and persuade him not to use violence. In the process of our user testing, we did not tell her how to use the pillow because we had marked it on the pillow in advance, but let her explore it by herself. She tried all the features as we expected, based on the hints we gave her. After user experience, we received feedback that the reaction was not sensitive after hitting the pillow, so we adjusted the range of pressure sensor to make it easier to feel pressure. At the same time, our users wanted us to make the character move, so we made the character’s arm move with the mouse, which I think was a nice change to make our character look more animated.

C.FABRICATION AND PRODUCTION:

The first problem we encountered in the process of making the pillow was the function of the pillow, and we discussed for a long time before deciding what kind of function we wanted the final pillow to have. We also wanted to add a tilt Sensor to detect if the user was shaking the pillow, triggering the character to shake his head in the screan. However, we were unable to add this feature because it doesn’t work. In the end, I think our biggest success this time is that our code works successfully. Since neither of us was good at writing code, we were worried about whether we could really finish the project at the beginning. However, during the production process, we kept learning and overcame every difficulty. Finally, our code worked successfully. I found the process really rewarding, and although tilt Sensor didn’t work properly in the end, I learned a lot while working on the final project. We use pressure sensor to feel the user’s blow on the pillow. We chose Button and Buzzer to give the user the option to play music. We chose Tilt Sensor to count the number of times users shook their pillows, although this element ultimately failed. We decided what features we wanted, and then we looked at our Kit box to see which elements would best implement our idea. We also wanted to have some bruise on Character’s face when hitting the pillow. But the reason we finally rejected this idea was that we didn’t think we could make Bruise very realistic. At the same time, technically, we thought it would take us too much time to write the code and the effect was not very obvious. Me and my partner Elaine, I made the circuit and the code of Arduino and our last video. Elaine made the Processing code.

D.CONCLUSIONS:

I think we achieved 90 percent of what we wanted. It worked pretty much as we expected during user testing. Our audience sees our marks when they use them and follows our instructions to explore our products. They managed to use every feature we designed and gave us a lot of useful feedback. I think my product align has my definition of Interaction. When my audience hits the pillow and presses the button, it is the input of our product, and then our product will give an output, which is also the feedback. But I think we have only achieved intermediate interaction. Although our character arm can move, the feedback of our product is already designed and can only provide feedback corresponding to input, instead of automatically giving different feedback according to different input of users. If I had more time, I would like to be able to get my Character to really move, to move around the screen freely, and to move the character around the screen randomly when the user moves the pillow. I think we should continue to improve our programming skills, and in the future I hope to be able to make my character truly communicate with the user. In my opinion, the success of our project basically met our expectations. I learned that we should not anticipate how terrible the difficulties are before we start. We should try to do it first and then constantly overcome the difficulties. Our success this time is a good case, to help me better build confidence. 

D.TECHNICAL DOCUMENTATION:

User Test Video:

 

Final Video:

Arduino Code:

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
#define REST      0
int press1=A0;
int press2=A1;
int shake=A3;
int button=13;
int buzzer=11;

int melody[] = {

  // Gren Hill Zone - Sonic the Hedgehog
  // Score available at https://musescore.com/user/248346/scores/461661
  // Theme by Masato Nakamura, arranged by Teddy Mason
  
  REST,2, NOTE_D5,8, NOTE_B4,4, NOTE_D5,8, //1
  NOTE_CS5,4, NOTE_D5,8, NOTE_CS5,4, NOTE_A4,2, 
  REST,8, NOTE_A4,8, NOTE_FS5,8, NOTE_E5,4, NOTE_D5,8,
  NOTE_CS5,4, NOTE_D5,8, NOTE_CS5,4, NOTE_A4,2, 
  REST,4, NOTE_D5,8, NOTE_B4,4, NOTE_D5,8,
  NOTE_CS5,4, NOTE_D5,8, NOTE_CS5,4, NOTE_A4,2, 




  
};
int 
//debounce
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin
int play;
int notDuration=0;
int notes = sizeof(melody) / sizeof(melody[0]) / 2;
// change this to make the song slower or faster
int tempo = 140;

// this calculates the duration of a whole note in ms
int wholenote = (60000 * 4) / tempo;

int divider = 0, noteDuration = 0;

//tilt sensor
const int SENSOR_PIN = 6;
int tiltVal;
int prevTiltVal;
int curls = 0;
//unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
//unsigned long debounceDelay = 10; 


void setup(){
  Serial.begin(9600);
  pinMode (buzzer, OUTPUT);
  pinMode (button, INPUT);
  pinMode(SENSOR_PIN, INPUT);//tilt sensor 
} 
void loop() {
  int pressRead1 = analogRead(press1);
  int pressRead2 = analogRead(press2);
  int buttonRead = digitalRead(button); //Put the reading value of the switch on botao
  if (buttonRead == HIGH)  {
    for ( int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) 
      {
        // calculates the duration of each note
        divider = melody[thisNote + 1];
        if (divider > 0) {
          // regular note, just proceed
          noteDuration = (wholenote) / divider;
        } else if (divider < 0) {
          // dotted notes are represented with negative durations!!
          noteDuration = (wholenote) / abs(divider);
          noteDuration *= 1.5; // increases the duration in half for dotted notes
        }
        // we only play the note for 90% of the duration, leaving 10% as a pause
        tone(buzzer, melody[thisNote], noteDuration * 0.9);
        // Wait for the specief duration before playing the next note.
        delay(noteDuration);
        // stop the waveform generation before the next note.
        noTone(buzzer);
      }
    }

 //tilt sensor
 int reading = digitalRead(SENSOR_PIN);
  // if the tilt sensor value changed, print the new value
  if (reading != prevTiltVal) {
    lastDebounceTime = millis();
    //Serial.println(tiltVal);
  }
  if ( (reading != tiltVal) && (millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer than the debounce
    // delay, so take it as the actual current state:
     tiltVal = reading;
    if (reading == HIGH) {
      curls = curls + 1;
      Serial.println(curls);
    }
  } 
  if (curls == 1) {
    Serial.println("Yay, you've done a set of curls");
    curls = 0;
  }
  prevTiltVal = reading;
  // for Serial Plotter use
  //Serial.println(tiltVal);
  //delay(1);

//pressure sensor
//  debounce & button for gloves to produce sounds
//if(pressRead1>150){
  //Serial.print(pressRead1);
  //Serial.print("   ");
//if(pressRead2>150){
 // Serial.print(pressRead2);
 // Serial.print("  ");
//  }
// }

//arduino to processing
int sensor1 = analogRead (A0); //pressure sensor 1//SCREAM
int sensor2 = analogRead (A1); //pressure sensor 2//TALKING
int sensor3 = digitalRead (6); //tilt sensor//TALKING

 // send the values keeping this format
  Serial.print(sensor1);
  Serial.print(",");  // put comma between sensor values
  Serial.print(sensor2);
  Serial.print(",");  // put comma between sensor values
  Serial.print(sensor3);
  Serial.println();
  
delay (100);

}

Processing Code:

 

import processing.serial.*;
import processing.sound.*;

int NUM_OF_VALUES_FROM_ARDUINO = 3;
int sensorValues [];

String myString = null;
Serial myPort;  //The serial port
//int sensorValue1; //pressure sensor 1 scream
//int sensorValue2; //pressure sensor 2 talk
//int sensorValue3; //tilt sensor talk

int radius = 100;
boolean playSound = true;
//declaring three soundfiles
SoundFile pscream;
SoundFile ptalk;
SoundFile ttalk;

//character
float x, y;
float angle1 = 0.0;
float angle2 = 0.0;
float segLength = 80;
float angle3 = 0.0;
float angle4 = 0.0;

void setup(){
size(800, 800);
background (100);
setupSerial();
 
 //create the object and load a sound into it
 pscream = new SoundFile (this, "pscream.wav"); //pressure sensor 1 scream
 ptalk = new SoundFile (this, "ptalk.wav"); //pressure sensor 2 talking
 ttalk = new SoundFile (this, "ttalk.wav"); //tilt sensor talking

//character
 x = width * 0.3;
 y = height * 0.5; 
}

void draw(){
 background (100);
 size (800,800); 
  
getSerialData();
printArray (sensorValues);
//character
 fill (255);
  strokeWeight (2);
  ellipse (400, 300, 150, 150); 
  //left eyeball
  fill (255);
  strokeWeight (2.5);
  ellipse (368, 290, 30, 30);
  //right eyeball
  fill (255);
  strokeWeight (2.5);
  ellipse (432, 290, 30, 30); 
  //left iris
  fill (0);
  ellipse (366, 290, 10, 12); 
  //right iris
  fill (0);
  ellipse (433, 290, 10, 12); 
  //mouth
  arc (400, 325, 40, 40, 0, PI);
//body
  fill (0);
  strokeWeight (2);
  arc (400, 577, 170, 400, HALF_PI+HALF_PI, TWO_PI);
//legs
  fill (255);
  rect(420, 575, 25, 100, 28);
  rect(360, 575, 25, 100, 28);  
//text  
fill (150, 100, 100, 250);
textSize(38);
textAlign(CENTER);
text("your pillow best friend", 400, 100);
//arms
  angle1 = (mouseX/float(width) - 0.5) * -PI;
  angle2 = (mouseY/float(height) - 0.5) * PI;
  angle3 = (mouseX/float(width) + 0.5) * + PI;
  angle4 = (mouseY/float(height) + 0.5) * PI;
  pushStyle();
  pushMatrix();
  strokeWeight(30);
  stroke(255, 160);
  segment(460, 430, angle1); 
  segment(segLength, 0, angle2);
  popMatrix();
  popStyle();
  pushStyle();
  pushMatrix();
  strokeWeight(30);
  stroke(255, 160);
  segment(350, 430, angle3); 
  segment(segLength, 0, angle4);
  popMatrix();
  popStyle();
  
//pressure sensor screaming
  if(sensorValues[0]>100){
    if(playSound == true) {
      pscream.play ();
      playSound = false;
rect(168, 165, 200, 50, 28);
fill (0);
textSize(25);
textAlign(LEFT);
text("AAAAAAAAA!!!!!!", 180, 200);
}
  else{
  //character face
  //head
  fill (255);
  strokeWeight (2);
  ellipse (400, 300, 150, 150); 
  //left eyeball
  fill (255);
  strokeWeight (2.5);
  ellipse (368, 290, 30, 30);
  //right eyeball
  fill (255);
  strokeWeight (2.5);
  ellipse (432, 290, 30, 30); 
  //left iris
  fill (0);
  ellipse (366, 290, 10, 12); 
  //right iris
  fill (0);
  ellipse (433, 290, 10, 12); 
  //mouth
  arc (400, 325, 40, 40, 0, PI);
//body
  fill (0);
  strokeWeight (2);
  arc (400, 577, 170, 400, HALF_PI+HALF_PI, TWO_PI);
//legs
  fill (255);
  rect(420, 575, 25, 100, 28);
  rect(360, 575, 25, 100, 28);  
//text  
fill (150, 100, 100, 250);
textSize(38);
textAlign(CENTER);
text("your pillow best friend", 400, 100);
//arms
  angle1 = (mouseX/float(width) - 0.5) * -PI;
  angle2 = (mouseY/float(height) - 0.5) * PI;
  angle3 = (mouseX/float(width) + 0.5) * + PI;
  angle4 = (mouseY/float(height) + 0.5) * PI;
  pushStyle();
  pushMatrix();
  strokeWeight(30);
  stroke(255, 160);
  segment(460, 430, angle1); 
  segment(segLength, 0, angle2);
  popMatrix();
  popStyle();
  pushStyle();
  pushMatrix();
  strokeWeight(30);
  stroke(255, 160);
  segment(350, 430, angle3); 
  segment(segLength, 0, angle4);
  popMatrix();
  popStyle();
  fill (255);
//textbubble
rect(168, 165, 200, 50, 28);
fill (0);
textSize(25);
textAlign(LEFT);
text("AAAAAAAAA!!!!!!", 180, 200);
  }
 }
//pressure sensor talking
  if(sensorValues[1]>100){
    if(playSound == true) {
      ptalk.play ();
      playSound = false;
fill (255);
rect(20, 165, 380, 50, 28);
fill (0);
textSize(20);
textAlign(LEFT);
text("buddy violence is not good let's talk it out", 35, 200);
    }
  else{
    //character face
    //head
  fill (255);
  strokeWeight (2);
  ellipse (400, 300, 150, 150); 
  //left eyeball
  fill (255);
  strokeWeight (2.5);
  ellipse (368, 290, 30, 30);
  //right eyeball
  fill (255);
  strokeWeight (2.5);
  ellipse (432, 290, 30, 30); 
  //left iris
  fill (0);
  ellipse (366, 290, 10, 12); 
  //right iris
  fill (0);
  ellipse (433, 290, 10, 12); 
  //mouth
  arc (400, 325, 40, 40, 0, PI);
//body
  fill (0);
  strokeWeight (2);
  arc (400, 577, 170, 400, HALF_PI+HALF_PI, TWO_PI);
//legs
  fill (255);
  rect(420, 575, 25, 100, 28);
  rect(360, 575, 25, 100, 28);  
//text  
fill (150, 100, 100, 250);
textSize(38);
textAlign(CENTER);
text("your pillow best friend", 400, 100);

//arms
  angle1 = (mouseX/float(width) - 0.5) * -PI;
  angle2 = (mouseY/float(height) - 0.5) * PI;
  
  angle3 = (mouseX/float(width) + 0.5) * + PI;
  angle4 = (mouseY/float(height) + 0.5) * PI;
 
  pushStyle();
  pushMatrix();
  strokeWeight(30);
  stroke(255, 160);
  segment(460, 430, angle1); 
  segment(segLength, 0, angle2);
  popMatrix();
  popStyle();
  
  pushStyle();
  pushMatrix();
  strokeWeight(30);
  stroke(255, 160);
  segment(350, 430, angle3); 
  segment(segLength, 0, angle4);
  popMatrix();
  popStyle();
//text bubble (PRESSURE2/PUNCHING)
fill (255);
rect(20, 165, 380, 50, 28);
fill (0);
textSize(20);
textAlign(LEFT);
text("buddy violence is not good let's talk it out", 35, 200);
  }
}
//tilt sensor talking
  if(sensorValues[2]>3){
    if(playSound == true) {
      ttalk.play ();
      playSound = false;
}
  else{
    //character
      //head
  fill (255);
  strokeWeight (2);
  ellipse (400, 300, 150, 150); 
  //left eyeball
  fill (255);
  strokeWeight (2.5);
  ellipse (368, 290, 30, 30);
  //right eyeball
  fill (255);
  strokeWeight (2.5);
  ellipse (432, 290, 30, 30); 
  //left iris
  fill (0);
  ellipse (366, 290, 10, 12); 
  //right iris
  fill (0);
  ellipse (433, 290, 10, 12); 
  //mouth
  arc (400, 325, 40, 40, 0, PI);
//body
  fill (0);
  strokeWeight (2);
  arc (400, 577, 170, 400, HALF_PI+HALF_PI, TWO_PI);
//legs
  fill (255);
  rect(420, 575, 25, 100, 28);
  rect(360, 575, 25, 100, 28);  
//text  
fill (150, 100, 100, 250);
textSize(38);
textAlign(CENTER);
text("your pillow best friend", 400, 100);

//arms
  angle1 = (mouseX/float(width) - 0.5) * -PI;
  angle2 = (mouseY/float(height) - 0.5) * PI;
  
  angle3 = (mouseX/float(width) + 0.5) * + PI;
  angle4 = (mouseY/float(height) + 0.5) * PI;
 
  pushStyle();
  pushMatrix();
  strokeWeight(30);
  stroke(255, 160);
  segment(460, 430, angle1); 
  segment(segLength, 0, angle2);
  popMatrix();
  popStyle();
  
  pushStyle();
  pushMatrix();
  strokeWeight(30);
  stroke(255, 160);
  segment(350, 430, angle3); 
  segment(segLength, 0, angle4);
  popMatrix();
  popStyle();
//text bubble (TILT/SHAKING)
fill (255);
rect(20, 165, 380, 50, 28);
fill (0);
textSize(20);
textAlign(LEFT);
text("hey buddy calm down, what's wrong?", 50, 200);
   }
  }  
}
void segment(float x, float y, float a) {
  translate(x, y);
  rotate(a);
  line(0, 0, segLength, 0);
}

void setupSerial() {
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[ 1 ], 9600);
  // WARNING!
  // You will definitely get an error here.
  // Change the PORT_INDEX to 0 and try running it again.
  // And then, check the list of the ports,
  // find the port "/dev/cu.usbmodem----" or "/dev/tty.usbmodem----" 
  // and replace PORT_INDEX above with the index number of the port.

  myPort.clear();
  // Throw out the first reading,
  // in case we started reading in the middle of a string from the sender.
  myString = myPort.readStringUntil( 10 );  // 10 = '\n'  Linefeed in ASCII
  myString = null;
  sensorValues = new int[NUM_OF_VALUES_FROM_ARDUINO];
}

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

recitation 10

Part 1:

At the beginning, I can’t build circuits properly. And then I realized that I probably used a wrong element so that the processing can’t use the data which was received fro the Arduino. Then, I change the element to potential-meter and finally it works.

Video:IMG_1370

Arduino Code:

int potmeterPin = A0;
int potmeterVal = 0;

void setup(){
Serial.begin(9600);
}

void loop(){

potmeterVal = analogRead(potmeterPin);

Serial.println(potmeterVal);

delay(100);
}


Processing Code:

 

import processing.serial.*;
PImage photo;

Serial mySerial;

String myString = null;
int nl = 10;
float myVal;

void setup(){
size(900,900);
String myPort = Serial.list() [2];
mySerial = new Serial(this, myPort, 9600);
photo = loadImage(“food.jpg”);
}

void draw(){

while (mySerial.available() >0) {
myString = mySerial.readStringUntil(nl);

if (myString != null){
background(255);
myVal = float(myString);

image(photo, 0, 0, myVal, myVal);

}
}
}


Part2:

In this recitation, I learned how to use the processing to control the camera and then show on the screen. I think that the hardest part of this is the code. I finished it under the help of my friend who was study in interaction lab lats semester to help me fixed some tiny problems in my code.

import processing.video.*;
String[] cameras = Capture.list();
Capture cam;
float b, pb;

import processing.sound.*;
SinOsc sine;
Env env;
float attackTime = 0.001;
float sustainTime = 0.004;
float sustainLevel = 0.3;
float releaseTime = 0.4;
int s = 20;

void setup() {
size(640, 480);
printArray(cameras);
cam = new Capture(this, cameras[0]);
cam.start();
sine = new SinOsc(this);
env = new Env(this);
//sine.play();
}
void draw() {
background(0);
if (cam.available()) {
cam.read();
}
color c = cam.get(width/2, height/2);
b = blue(c);
float difference = abs(b-pb);
for (int i=0; i<width; i = i + s) {
for (int j=0; j<height; j = j + s) {
float size = map(b, 0, 255, 5, 80);
color all =cam.get(i, j);
fill(all);
noStroke();
rect(i, j, size, size);
}
}
if (difference>10) {
sine.play();
sine.freq(map(b, 0, 255, 100, 800));
env.play(sine, attackTime, sustainTime, sustainLevel, releaseTime);
}
pb=b;
}

 

Video:Screen Recording 2022-05-20 at 10.35.17 AM

 

Recitation9

 

Exercise 1:

Processing Code:

import processing.sound.*;

// declare a SoundFile object
SoundFile sound1;
SoundFile sound2;
SoundFile sound3;
SoundFile sound4;
boolean step1= false;
boolean step2= false;

void setup() {
  size(1200, 1000);
  // create the object and load a file into it
  sound1 = new SoundFile(this, "crashbreak2rideout.wav");

  sound3 = new SoundFile(this, "kickcrash.wav");
 
  background(255);
}

void draw() {
  if (keyPressed) {
    
    
    if (key == 'd' || key == 'D') {
      sound3.loop();
      noStroke();
      fill(#500B6C);
      rect(500, 300, 100, 100);
      fill(255);
    
    }
   
  }
}
void keyPressed(){
  if (key == 'b' || key == 'B') {
    step1=!step1;
  }
      if (step1==true) {
        sound1.loop();
        
        fill(#500B6C);
        noStroke();
     
        rect(700, 300, 100, 100);
    
    
      } else {
        sound1.stop();
         
        fill(255);
        noStroke();
        circle(400, 500, 62);
        
      }
    
  
    }

Video:IMG_1326

 

 

Exercise2:

Arduino Code:

// IMA NYU Shanghai
// Interaction Lab

/**
This example is to send multiple values from Processing to Arduino.
You can find the Processing example file in the same folder which works with this Arduino file.
**/
#define ZD 3
#define NUM_OF_VALUES_FROM_PROCESSING 1 /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/

/** DO NOT REMOVE THESE **/
int tempValue = 0;
int valueIndex = 0;

/* This is the array of values storing the data from Processing. */
int processing_values[NUM_OF_VALUES_FROM_PROCESSING];
#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = A0; // analog pin used to connect the potentiometer
int val;

void setup() {
Serial.begin(9600);
pinMode(ZD,OUTPUT);

}

void loop() {
getSerialData();
analogWrite(ZD,200);
delay(5000);
analogWrite(ZD,0);
delay(1000);
analogWrite(ZD,100);
delay(5000);
analogWrite(ZD,0);
delay(1000);
// add your code here using elements in the values array

//this is an example connecting a buzzer to pin 8
/*
if (processing_values[0] == 1) {
//turn on an LED when the mouse is pressed
digitalWrite(13, HIGH);
// map values from mouseX to frequency from (0 – 500 pixels)
//to the output pitch range (120 – 1500Hz)
int f = map(processing_values[1], 0, 500, 120, 1500);
// map values from mouseY to frequency from (0 – 500 pixels)
//to the output duration range (10 – 2000 milliseconds)
int d = map(processing_values[2], 0, 500, 10, 2000);
// play the pitch:
tone(8, processing_values[1], processing_values[2]);
delay(1); // delay in between reads for stability
} else {
digitalWrite(13, LOW);
}
*/
//end of example

}
//receive serial data from Processing
void getSerialData() {
while (Serial.available()) {
char c = Serial.read();
//switch – case checks the value of the variable in the switch function
//in this case, the char c, then runs one of the cases that fit the value of the variable
//for more information, visit the reference page: https://www.arduino.cc/en/Reference/SwitchCase
switch (c) {
//if the char c from Processing is a number between 0 and 9case ‘0’…’9′:
//save the value of char c to tempValue
//but simultaneously rearrange the existing values saved in tempValue
//for the digits received through char c to remain coherent
//if this does not make sense and would like to know more, send an email to me!tempValue = tempValue * 10 + c – ‘0’;
break;
//if the char c from Processing is a comma
//indicating that the following values of char c is for the next element in the values arraycase ‘,’:
// processing_values[valueIndex] = tempValue;
//reset tempValue value
tempValue = 0;
//increment valuesIndex by 1
valueIndex++;
break;
//if the char c from Processing is character ‘n’
//which signals that it is the end of datacase ‘\n’:
//save the tempValue
//this will b the last element in the values array
// processing_values[valueIndex] = tempValue;
//reset tempValue and valueIndex values
//to clear out the values array for the next round of readings from Processing
tempValue = 0;
valueIndex = 0;
break;
}
}
}

Processing code: 

import processing.serial.*;
import processing.sound.*;

int NUM_OF_VALUES_FROM_ARDUINO = 1; /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/
int sensorValues[]; /** this array stores values from Arduino **/

String myString = null;
Serial myPort;

// declare an AudioIn object
SoundFile sound;
// declare an Amplitude analysis object to detect the volume of sounds
Amplitude analysis;

void setup() {
size(500, 500);
sound= new SoundFile(this, "crashbreak2rideout.wav");

sound.play();
// create the Amplitude analysis object

// use the microphone as the input for the analysis
analysis = new Amplitude(this);
analysis.input(sound);

setupSerial();
}

void draw() {
background(0);
println(analysis.analyze());
background(0);
float volume = analysis.analyze();
// map the volume value to a useful scale
float diameter = map(volume, 0, 1, 0, width);
// draw a circle based on the microphone amplitude (volume)
circle(width/2, height/2, diameter);
getSerialData();
sensorValues[0]=int(map(analysis.analyze(),0,1,0,200));
}

void setupSerial() {
printArray(Serial.list());
myPort = new Serial(this, Serial.list( )[4], 9600);

myPort.clear();
myString = myPort.readStringUntil( 10 ); // 10 = ‘\n’ Linefeed in ASCII
myString = null;

sensorValues = new int[NUM_OF_VALUES_FROM_ARDUINO];
}

void getSerialData() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil( 10 ); // 10 = ‘\n’ Linefeed in ASCII
if (myString != null) {
String[] serialInArray = split(trim(myString), ",");
if (serialInArray.length == NUM_OF_VALUES_FROM_ARDUINO) {
for (int i=0; i<serialInArray.length; i++) {
sensorValues[i] = int(serialInArray[i]);
}
}
}
}
}

 

 
Video:
IMG_1336

Homework:

video:IMG_1332

Arduino Code 

// IMA NYU Shanghai
// Interaction Lab

/**
This example is to send multiple values from Processing to Arduino.
You can find the Processing example file in the same folder which works with this Arduino file.
**/
#define ZD 3
#define NUM_OF_VALUES_FROM_PROCESSING 1 /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/

/** DO NOT REMOVE THESE **/
int tempValue = 0;
int valueIndex = 0;

/* This is the array of values storing the data from Processing. */
int processing_values[NUM_OF_VALUES_FROM_PROCESSING];
#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = A0; // analog pin used to connect the potentiometer
int val;

void setup() {
Serial.begin(9600);
pinMode(ZD,OUTPUT);

}

void loop() {
getSerialData();
analogWrite(ZD,200);
delay(5000);
analogWrite(ZD,0);
delay(1000);
analogWrite(ZD,100);
delay(5000);
analogWrite(ZD,0);
delay(1000);
// add your code here using elements in the values array

//this is an example connecting a buzzer to pin 8
/*
if (processing_values[0] == 1) {
//turn on an LED when the mouse is pressed
digitalWrite(13, HIGH);
// map values from mouseX to frequency from (0 – 500 pixels)
//to the output pitch range (120 – 1500Hz)
int f = map(processing_values[1], 0, 500, 120, 1500);
// map values from mouseY to frequency from (0 – 500 pixels)
//to the output duration range (10 – 2000 milliseconds)
int d = map(processing_values[2], 0, 500, 10, 2000);
// play the pitch:
tone(8, processing_values[1], processing_values[2]);
delay(1); // delay in between reads for stability
} else {
digitalWrite(13, LOW);
}
*/
//end of example

}
//receive serial data from Processing
void getSerialData() {
while (Serial.available()) {
char c = Serial.read();
//switch – case checks the value of the variable in the switch function
//in this case, the char c, then runs one of the cases that fit the value of the variable
//for more information, visit the reference page: https://www.arduino.cc/en/Reference/SwitchCase
switch (c) {
//if the char c from Processing is a number between 0 and 9case ‘0’…’9′:
//save the value of char c to tempValue
//but simultaneously rearrange the existing values saved in tempValue
//for the digits received through char c to remain coherent
//if this does not make sense and would like to know more, send an email to me!tempValue = tempValue * 10 + c – ‘0’;
break;
//if the char c from Processing is a comma
//indicating that the following values of char c is for the next element in the values arraycase ‘,’:
// processing_values[valueIndex] = tempValue;
//reset tempValue value
tempValue = 0;
//increment valuesIndex by 1
valueIndex++;
break;
//if the char c from Processing is character ‘n’
//which signals that it is the end of datacase ‘\n’:
//save the tempValue
//this will b the last element in the values array
// processing_values[valueIndex] = tempValue;
//reset tempValue and valueIndex values
//to clear out the values array for the next round of readings from Processing
tempValue = 0;
valueIndex = 0;
break;
}
}
}

Processing Code

import processing.sound.*;
AudioIn microphone;
Amplitude analysis;
float r;
void setup() {
  size(600, 400);
  microphone = new AudioIn(this, 0);
  microphone.start();
  analysis = new Amplitude(this);
  analysis.input(microphone);
}

void draw() {
  println(analysis.analyze());
  background(#FFFFFC);
  float volume = analysis.analyze();
  float r= map(volume, 0, 1, 255, 0);
  float d=map(volume, 0, 1, 0, 100);
  fill(255, r, 64);
  ellipse(300, 200, 200, 200);
  fill(#FA0810);
  strokeWeight(5);
  line(290,260,300,260);
  fill(0);
  ellipse(280,180,5,5);
  ellipse(320,180,5,5);
}

STEP3 : ESSAY

A. PROJECT TITLE

Pillow Best Friend

 

B. PROJECT STATEMENT OF PURPOSE *

Nowadays, people are stressed out by high pressure of contemporary society. Teenagers obtain the pressure from school, they finish their assignments before the deadline and struggle on getting higher grades. Graduate students need to find a big company and an internship job to earn a higher salary. Employees need to do overtime work to make their boss satisfied for them to get an opportunity for promotion and salary increase. It seems like everyone in this society are living under pressure. At the end of the day, people can only relax and take off the fatigue of the day when they are in bed. But poor sleep is still a common problem in modern society. Therefore, we want to make a multi-functional pillow to help people rest and be able to let out their stress.

 

C. PROJECT PLAN *

Our project aims to help people in contemporary society who are stressed out by high-pressure work. Before we formally start the project, we will make a diagram and some prototypes to make sure that the whole project will go smoothly. (will finish this by May 1st). After we finish the preliminary work, we will start to write the code and build the cirucuts following the diagram (will end this by May 5th). After all, these are finished, we will add some text and marks on our project to give our tester the clue to navigate them explore our project . (will finish this by May 7th). Lastly, we will make a film about our project to give a complete story of our project. (will end this by May 10th before class).

D. CONTEXT AND SIGNIFICANCE

 

According to my research, the average sleep time of human is 8 hours a day which indicate that a third of the time in our life is in bed. Especially people in the contemporary society need to face varieties of high-pressure missions in daily life, pillow is the last peaceful place for them. Thus, we want to make this pillow to give it several functions depending on the skills we learned in class. At the time that we punch the pillow, a character on-screen will give feedback that is trying to advocate “no violence”. This really aligns with my definition of interaction which contains the input and output feedback. We are trying to show that sleep is significant for modern people, they need to focus on their inside mental health more. For us, we are trying to give the pillow more function and make it more entertaining instead of just an average pillow. For whom is your project intended and why is it of special value to its targeted audience? Our targeted audience is all the modern people who aren’t sleeping well

Recitation 8

Exercise1:

video:

code:

Arduino:

// IMA NYU Shanghai
// Interaction Lab
// For sending multiple values from Arduino to Processing


void setup() {
  Serial.begin(9600);
}

void loop() {
  // to send values to Processing assign the values you want to send
  //this is an example
  int sensor1 = analogRead(A0);
  int sensor2 = analogRead(A1);
  //int sensor3 = analogRead(A2);

  // send the values keeping this format
  Serial.print(sensor1);
  Serial.print(",");  // put comma between sensor values
  Serial.print(sensor2);
  //Serial.print(",");  // put comma between sensor values
  //Serial.print(sensor3);
  Serial.println(); // add linefeed after sending the last sensor value

  // too fast communication might cause some latency in Processing
  // this delay resolves the issue.
  delay(100);

  // end of example sending values
}

Processing:

  background(0);
}

void draw() {
  getSerialData();
  printArray(sensorValues);  
  x = map(sensorValues[0],0,1023,0,width);
  y = map(sensorValues[1],0,1023,0,width);

  stroke(255);
  line(sensorp[0], sensorp[1],x, y);
  sensorp[0]=int(x);
  sensorp[1]=int(y);
}

void setupSerial() {
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[1], 9600);
  
  myPort.clear();
  myString = myPort.readStringUntil( 10 );  // 10 = '\n'  Linefeed in ASCII
  myString = null;

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



 

Exercise 2:

video:

 

 

Arduino:

#define NUM_OF_VALUES_FROM_PROCESSING 1 /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/
#include <Servo.h>
/** DO NOT REMOVE THESE **/
int tempValue = 0;
int valueIndex = 0;
bool prevState = false;
bool currentState = false;
Servo myservo;
int processing_values[NUM_OF_VALUES_FROM_PROCESSING];

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  myservo.attach(11);
  }

void loop() {
getSerialData();
  currentState = processing_values[0];
  if (currentState != prevState && currentState == 1) {
    myservo.write(90);
    delay(100);
    myservo.write(0);
  } else {
    myservo.write(0);
  }
  prevState = currentState;
  }
  //receive serial data from Processing
 void getSerialData() {
  while (Serial.available()) {
    char c = Serial.read();
    switch (c) {
      case '0'...'9':
        tempValue = tempValue * 10 + c - '0';
        break;
      case ',':
        processing_values[valueIndex] = tempValue;
        tempValue = 0;
        valueIndex++;
        break;
      case '\n':
        processing_values[valueIndex] = tempValue;
        tempValue = 0;
        valueIndex = 0;
        break;
    }
  }
 }

processing:

import processing.serial.*;
float x;
float y;

int NUM_OF_VALUES_FROM_ARDUINO = 2;   /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/
int sensorValues[];      /** this array stores values from Arduino **/
int sensorp[];
String myString = null;
Serial myPort;

void setup() {
  size(500, 500);
  setupSerial();
  sensorp = new int[NUM_OF_VALUES_FROM_ARDUINO];
import processing.serial.*;
int NUM_OF_VALUES_FROM_PROCESSING = 1;  /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/int processing_values[] = new int[NUM_OF_VALUES_FROM_PROCESSING]; /** this array stores values you might want to send to Arduino **/
Serial myPort;
String myString;
int x=40;
int speedX = 7;

void setup() {
  fullScreen();
  background(0);
  setupSerial();
}
void draw() {
  background(0);
  circle (x, 200, 80);
  x= x+speedX;
  if (x > width-40 || x < 0+40) {
    speedX = -speedX;
  }
  if (x > width-40) {
    processing_values[0] = 1;
  } else {
    processing_values[0] = 0;
  }
  sendSerialData();
}
void setupSerial() {
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[1], 9600);
  myPort.clear();
  myString = myPort.readStringUntil( 10 );  // 10 = '\n'  Linefeed in ASCII
  myString = null;
}
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
    }
    else {
      data += "\n"; // add the end of data character linefeed "\n"
    }
  }
  //write to Arduino
  myPort.write(data);
  print(data); // this prints to the console the values going to arduino
}

Homework:

video:

  

Arduino:
// IMA NYU Shanghai
// Interaction Lab
// For sending multiple values from Arduino to Processing

int buttonPin1 = 3;
int buttonPin2 = 4;

int counter1 = 0;
int counter2 = 0;

int buttonState1 = 0;
int buttonState2 = 0;

int prevState1 = 0;
int prevState2 = 0;


void setup() {
  Serial.begin(9600);
}

void loop() {
  // to send values to Processing assign the values you want to send
  //this is an example
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);

  if (buttonState1 == 1) {
    if (buttonState1 != prevState1) {
      counter1 += 1;
    }
  }
  prevState1 = buttonState1;
  
  if (buttonState2 == 1) {
    if (buttonState2 != prevState2) {
      counter2 += 1;
    }
  }
  prevState2 = buttonState2;
  
  // send the values keeping this format
  Serial.print(counter1);
  Serial.print(",");  // put comma between sensor values
  Serial.print(counter2);
  //  Serial.print(",");  // put comma between sensor values
  //  Serial.print(sensor3);
  Serial.println(); // add linefeed after sending the last sensor value

  // too fast communication might cause some latency in Processing
  // this delay resolves the issue.
  delay(100);

  // end of example sending values
}

Processing:

// IMA NYU Shanghai
// Interaction Lab
// For receiving multiple values from Arduino to Processing

/*
 * Based on the readStringUntil() example by Tom Igoe
 * https://processing.org/reference/libraries/serial/Serial_readStringUntil_.html
 */

import processing.serial.*;


int NUM_OF_VALUES_FROM_ARDUINO = 2;   /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/
int sensorValues[];      /** this array stores values from Arduino **/

String myString = null;
Serial myPort;

void setup() {
  size(600, 600);
  background(0);
  setupSerial();
}

void draw() {
  background(0);
  getSerialData();
  printArray(sensorValues);

   if (sensorValues[0] % 2 == 1){
    pushMatrix();
    fill(255);
    translate(width*0.3, height*0.3);
    rotate(frameCount / 200.0);
    star(0, 0, 30, 70, 5);
    popMatrix();
  } else {
    fill(0);
  }

  if (sensorValues[1] % 2 == 1) {
    pushMatrix();
    fill(255);
    translate(width*0.7, height*0.7);
    rotate(frameCount / 200.0);
    star(0, 0, 80, 100, 40);
    popMatrix();
  } else {
    fill(0);
  }
  
}

void setupSerial() {
  //printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[1], 9600);
  // WARNING!
  // You will definitely get an error here.
  // Change the PORT_INDEX to 0 and try running it again.
  // And then, check the list of the ports,
  // find the port "/dev/cu.usbmodem----" or "/dev/tty.usbmodem----"
  // and replace PORT_INDEX above with the index number of the port.

  myPort.clear();
  // Throw out the first reading,
  // in case we started reading in the middle of a string from the sender.
  myString = myPort.readStringUntil( 10 );  // 10 = '\n'  Linefeed in ASCII
  myString = null;

  sensorValues = new int[NUM_OF_VALUES_FROM_ARDUINO];
}


void getSerialData() {
  while (myPort.available() > 0) {
    myString = myPort.readStringUntil( 10 ); // 10 = '\n'  Linefeed in ASCII
    if (myString != null) {
      String[] serialInArray = split(trim(myString), ",");
      if (serialInArray.length == NUM_OF_VALUES_FROM_ARDUINO) {
        for (int i=0; i<serialInArray.length; i++) {
          sensorValues[i] = int(serialInArray[i]);
        }
      }
    }
  }
}
void star(float x, float y, float radius1, float radius2, int npoints) {
  float angle = TWO_PI / npoints;
  float halfAngle = angle/2.0;
  beginShape();
  for (float a = 0; a < TWO_PI; a += angle) {
    float sx = x + cos(a) * radius2;
    float sy = y + sin(a) * radius2;
    vertex(sx, sy);
    sx = x + cos(a+halfAngle) * radius1;
    sy = y + sin(a+halfAngle) * radius1;
    vertex(sx, sy);
  }
  endShape(CLOSE);
}

STEP 2: PROJECT PROPOSAL POSTED ON

Idea One

A. Digital Ping Pong

B. Our first idea was to make a game that emulates the sport table tennis or ping pong. This game is divided into two parts. The first part which is based on Processing, will have a ball that can move randomly on the screen. Then in the middle of the screen it is separated by a line (which will be like the net on a ping pong table). In the second part, we want to make a movable ping pong paddle made with Arduino. When the ball touches the edge, the paddle moves to the position of the ball to trigger the ball to rebound. If the paddle doesn’t catch the ball then it will go off the edge and the other team scores a point. As the game progresses, the ball moves faster and faster. This is a game that you can play at home during quarantine.

C.
 

Idea Two

A. Falling Pacman

B. For this project idea we were inspired by the game of Pacman (mainly the character itself and how it swallows the dots). We were thinking about having a big Pacman eating small Pacmans but making it a game for two. There will be one big one on each side of the screen and they will move horizontally to eat the falling/bouncing/moving small Pacmans. Whoever eats the most wins. As for how each player will make the big Pacman eat we will use an ultrasonic ranger and use the distance to represent moving left or right. This project is purely entertainment and will be a fun game for whenever someone is bored. It can even be a game for one to try and reach the highest number of eats.

C.

Idea Three

A. Picture & Jeopardy Game

B. In this third idea we have a whole concept of a game with multiple parts to it (will require multiple players). First you will need to play a game of guessing the picture (on processing we will have a hidden picture and black sections on it to cover the majority of it, when you press a button on the arduino you will reveal a section of the picture). Whoever guesses the picture right will be able to move onto the next part of the game. On a separate laptop and processing and arduino there will be a game of jeopardy. There will be two buttons (yes or no) and leds on the arduino and then on processing we have a black screen with boxes/grid pattern that when we choose a box there will be a question inside and we will see who gets the question first (by playing a game of pressing the button the fastest or reaching a certain number of presses). The players will need to guess a new picture for each question. The person with the most points will win. With this whole experience you can host game nights at home at any time.

C.
 

Idea Four

A. Stress Puncher

B. For our last idea we thought of making something that would help you de-stress. We will have gloves that will include pressure sensors and when you punch towards the screen you will see bruises that appear on the processing screen due to the pressure used in the process. If you feel like you need to let go of feelings or letting it out, this is a great way to express it and you might even get some exercise in as well!

C.

Recitation 7

Step 1

float x = 20;
float y = 30;
float stepX = 48;
float stepY = 20;

void setup() {
  size(800, 800);
  background(41,227,216);
}

void draw() {
for(int i=0;i<width;i+=150){
    for (int j=0;j<height;j+=60){
      drawFish(i, j, 4, color(150,183,181));
    }
  }
}

void drawFish(float u, float v, float s, color c) {
  stroke(22,55,106);
  fill(c);
  triangle(u, v, u+20, v+10, u+20, v-10);
  triangle(u+20, v+10, u+20, v-10, u+80, v);
  triangle(u+80, v, u+90, v+6, u+90, v-6);
  fill(255);
  circle(u+13, v-3, s); 
  circle(u-6, v, s*1.4); 
  circle(u-6, v-10, s*1.8); 
  circle(u-6, v-26, s*2.2); 
}

 

 

 

Step 2

Below is my code for recitation 7.
 

  
int count = 10;
float x[] = new float [count];
float y[] = new float [count];
int size [] = new int [count];
float r[] = new float [count];
float g[] = new float [count];
float b[] = new float [count];
color heartColor[] = new color[count];    
float xspeed[] = new float [count];
float yspeed[] = new float [count];
float k;
float f;
float z;
void setup () {
  size(800, 800);
  background(255, 255, 255);
 
}

void draw () {
   for ( int i=0; i < x.length; i++) {
    // set value for position x and y
    x[i] = random (100, width-100);
    y[i] = random (100, height-100);
    // set value for size
    size[i] = round(random( 50, 100));
    r[i] = random(0,255);
    g[i] = random(0,255);
    b[i] = random(0,255);
    heartColor[i] = color(r[i], g[i], b[i]);
    xspeed[i] = random ( 3);
    yspeed[i] = random ( 3);
  }
  k= random (0,255);
f= random (0,255);
z= random (0,255);
  background (k,f,z);
  fill(100, 150, 100);
  for ( int i=0; i < x.length; i++) {
    Heart(x[i], y[i], size[i], heartColor[i]);
   move();
    bounce();
  }
}

void move() {

  for ( int i=0; i < x.length; i++) {
    x[i] += xspeed[i] ;
    y[i]  += yspeed[i] ;
  }
}

void bounce() {

  for ( int i=0; i < x.length; i++) {
    if ( x[i] <= 0 + size[i]/2 || x[i]>= width - size[i]/2 ) {
      xspeed[i] = -xspeed[i];
    }

    if ( y[i] <= 0+ size[i]/2 || y[i]>= height - size[i]/2 ) {
      yspeed[i] = -yspeed[i];
    }
  }
}

void Heart(float _x, float _y, int _size, color _heartColor){
  fill(_heartColor);
  beginShape();
  curveVertex(_x+50, _y+200);
  curveVertex(_x+50, _y+90);
  curveVertex(_x+10, _y+50);
  curveVertex(_x+25, _y+25);
  curveVertex(_x+50, _y+33);
  curveVertex(_x+50, _y+100);
  endShape();
  beginShape();
  curveVertex(_x+50, _y+100);
  curveVertex(_x+50, _y+33);
  curveVertex(_x+75, _y+25);
  curveVertex(_x+90, _y+50);
  curveVertex(_x+50, _y+90);
  curveVertex(_x+50, _y+200);
  endShape();
  
}

Step 2

Q1: In the reading “Art, Interaction and Engagement” by Ernest Edmonds, he identifies four situations in an interactive artwork: ‘Static’, ‘Dynamic-Passive’, ‘Dynamic-Interactive’ and ‘Dynamic-Interactive(Varying)’. From the exercise, you did today which situations do you identify in every part you executed? Explain.
I think that my work, it’s between “Dynamic-passive” and “Dynamic interactive.” “The internal mechanism is specified by the artist and any changes that take place are entirely predictable”(3). My code does not meet this premise that its color and moving direction are not predictable. I use the Random model to change the color of the heart and set the background color as random in the loop to make a shiny result. But for the next level “Dynamic interactive,” the premise of “the human ‘viewer’ has an active role in influencing the changes in the art object.” For my project, the viewer can’t make the change in the art object, after starting the program, it will play automatically.

 

Q2: What is the benefit of using arrays? How might you use arrays in a potential project?

“Arrays can be created to hold any type of data, and each element can be individually assigned and read.” The data for Arrays set up first is flexible, all the elements can be declared by myself. And also in the following code, I can just use the number that I store in the first instead of repeating writing it, to make my code more precise. In my potential project, I might store user data in arrays to make my poster more vivid。

PREPARATORY RESEARCH AND ANALYSIS

  • I find two projects on Google, first one is called ”click canvas,” which is a project that contains several buttons with random colors. When creating this product, the creators hope to add music and art elements to the product at the same time, so they use Arduino to make buttons with different colors. When interacting with the product, the audience can change the color of the button for multiple clicks, and then the first click of other buttons will follow the color of the previous click. At the same time, the stereo will play different sounds according to different colors, and the audience can enjoy the music they create while painting.

 

  •   And another one is called “SBC”. This work is a combination of Processing and Arduino. This work allows the audience to draw on the touch screen. After painting, the symbols will swim freely on the screen. This inspired me that I can combine Processing and Arduino to make a similar competitive game so that my products can move freely on the screen. At the same time, make a paddle based on Arduino that can interact with the “stuff” on the screen.

 

  • For me, I made a definition of interaction in my first blog that interaction is feedback. Now I want to add that interaction is the feedback plus input, Because since my first project the “main brain”, I noticed that only the output can’t complete the whole process of “interaction.” We need to transmit the emotion ball as the “ input” and also get the output which is the feedback from our main brain. “Interactive art systems involve artifacts and audiences equally. The artist sets up situations that develop in ways that are, at least in part, determined by the audience.”(16) Just like our midterm project “the lonely love,” different audience received different melody from the project. The audience’s different behavior becomes the variate of our project, which also completes the system of our interactive arts.

Work CiteArt

Interaction and Engagement, Ernest Edmonds,2011

A simple interactive project with processing on SBC. Arduino Project Hub. (n.d.). Retrieved April 14, 2022, from https://create.arduino.cc/projecthub/haoming-weng/a-simple-interactive-project-with-processing-on-sbc-6f593a?ref=tag&ref_id=interactive&offset=5

 

RECITATION 6: Leander’s Report

This is the interactive poster I did for this week’s recitation project:

Below are my code:
float r;
float g;
float b;
float xposition=width/3;
float xposition2=width/3;
float yposition=height/3;
float yposition2=height/3;



void setup(){
  size (800,800); 
  background(255);
}
void draw(){
 
  textSize(40);
  textAlign(CENTER);
  text("IMA SPRING 22 END-OF-SEMESTER",width/2,height/3 +50);
  
  textSize(30);
textAlign(CENTER);
text("Time:6pm to 8pm", width/2,height/2 +50);
textSize(30);
textAlign(CENTER);
text("Day:Friday May 13th", width/2,height/2 +100);
  xposition=xposition+1;
  rect(xposition, height/2,100,100);


  fill (r,g,b);
  r=random(0,255);
    g=random(0,255);
      b=random(0,255);
   
   rect(width/2, yposition2,100,100);
  yposition2=yposition2+1;
  fill (r,g,b);
  r=random(0,255);
    g=random(0,255);
      b=random(0,255);
   
   rect(width/3, yposition,100,100);
  yposition=yposition+1;
  fill (r,g,b);
  r=random(0,255);
    g=random(0,255);
      b=random(0,255);
   
   rect(xposition2, height/3,100,100);
  xposition2=xposition2+1;
  fill (r,g,b);
  r=random(0,255);
    g=random(0,255);
      b=random(0,255);
      
       ellipse(mouseX,mouseY,50,50);
  fill(r,g,b);  }

For this week, I took a long time to review the knowledge we learned about Processing. One thing is that I need to check several times to make sure the project meets my original idea. Because I’m not that familiar with coding, I need to take a long time to fix some small problems with my code. But the final result made me really glad.

Midterm individual reflection

THE LONELY LOVE

A. Project Title – The Lonely Love 
    Group Members  – Leander&Vivan
    Instructor – Andy

B.The Context and Significance.

In today’s high-stress environment when people are faced with different social situations, they’re used to pretending and repressing their felling in order to seem less lonely and fit in with the group and environment around them. Especially in megacities like Shanghai and New York, people shuttle in different boxes every day, their souls are constantly repressed and not released. People have been used to ignoring their inner feelings, switching masks in front of different people. The data of our pre-design study found that the rate of depression in China is as high as 4.98%, while in Shanghai it is as high as 10.27%.

Conception and Design

Therefore, in order to expose this aspect of social problems, we came up with the idea of making such an art piece that expresses people’s inner loneliness through the form of music. The product is made up of two parts, gloves and clothes. They represent the difference between the emotions people express and real emotions. They express their emotions through different kinds of music. The idea is that when performers wear gloves, the gloves represent their facial expressions, and how they behave in front of different social groups. And their true feelings are hidden. They express their true feelings only when the person closest to them gives them a hug.

Fabrication and Production

When the performer wearing a glove and shakes hands with someone, the pressure sensor in the right-hand picks up the pressure and passes the signal to the buzzer in the glove which is set off, and music is played. The left-hand glove has a button that can choose to control different music to represent their different mood. But when the audience hugs the performer, the pressure sensors in the heart on the clothes trigger and a buzzer plays sad music to express his inside true feelings. The difference between the sound of the glove and the sound of the heart means that the emotions people express are not the same as the real emotions they feel inside. Our hearts were cut out of cardboard and then glued together with a glue gun and colored with pigment. My partner Vivan and I split our responsibilities. She was responsible for writing coding to meet our product requirements, and I was responsible for constructing circuits and making products manually. In this process, the biggest problem is that the community has started lockdown and because my partner and I are in different places we can only communicate online. Moreover, many of the materials we need cannot be received in time. Therefore, we try our best to make use of the surrounding waste materials to make our products.

Conclusion

I think the result of our final product presentation is not bad, the whole is in line with our idea. The only problem is that the heart can’t switch between styles of music like a glove. But we can certainly solve this problem if we have more time and materials. At the end of the day, we hope to use our project to appeal to more people to pay attention to their inside, release themselves more rather than wrong themselves, and make their lives better.

 

 

#include "pitches.h"

//LED for heart 
int led=13;
int press1=A1;
int press2=A2;
int buzzer1=3;
int buzzer2=6;
int vibrate=2; 
int brightness=0;
int fadeAmount = 5; 
int button=9;
int lastcount;
int tempo = 76;
int tempo2 = 200;
int tempo3 = 80;
  
  
//#define vibOutPin 2;

//debounce
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 800;    // the debounce time; increase if the output flickers
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

//press the button how many times
int count=0;
bool firstClick=false;
bool secondClick=false;

// notes in the melody:
int melody[] = {

  // Wiegenlied (Brahms' Lullaby)
  // Score available at https://www.flutetunes.com/tunes.php?id=54

  NOTE_G4, 4, NOTE_G4, 4, //1
  NOTE_AS4, -4, NOTE_G4, 8, NOTE_G4, 4,
  NOTE_AS4, 4, REST, 4, NOTE_G4, 8, NOTE_AS4, 8,
  NOTE_DS5, 4, NOTE_D5, -4, NOTE_C5, 8,
  NOTE_C5, 4, NOTE_AS4, 4, NOTE_F4, 8, NOTE_G4, 8,
  NOTE_GS4, 4, NOTE_F4, 4, NOTE_F4, 8, NOTE_G4, 8,
  NOTE_GS4, 4, REST, 4, NOTE_F4, 8, NOTE_GS4, 8,
  NOTE_D5, 8, NOTE_C5, 8, NOTE_AS4, 4, NOTE_D5, 4,

  NOTE_DS5, 4, REST, 4, NOTE_DS4, 8, NOTE_DS4, 8, //8
  NOTE_DS5, 2, NOTE_C5, 8, NOTE_GS4, 8,
  NOTE_AS4, 2, NOTE_G4, 8, NOTE_DS4, 8,
  NOTE_GS4, 4, NOTE_AS4, 4, NOTE_C5, 4,
  NOTE_AS4, 2, NOTE_DS4, 8, NOTE_DS4, 8,
  NOTE_DS5, 2, NOTE_C5, 8, NOTE_GS4, 8,
  NOTE_AS4, 2, NOTE_G4, 8, NOTE_DS4, 8,
  NOTE_AS4, 4, NOTE_G4, 4, NOTE_DS4, 4,
  NOTE_DS4, 2

};

int melody2[] = {

  // Minuet in G - Petzold
  // Score available at https://musescore.com/user/3402766/scores/1456391
  NOTE_D5,4, NOTE_G4,8, NOTE_A4,8, NOTE_B4,8, NOTE_C5,8, //1
  NOTE_D5,4, NOTE_G4,4, NOTE_G4,4,
  NOTE_E5,4, NOTE_C5,8, NOTE_D5,8, NOTE_E5,8, NOTE_FS5,8,
  NOTE_G5,4, NOTE_G4,4, NOTE_G4,4,
  NOTE_C5,4, NOTE_D5,8, NOTE_C5,8, NOTE_B4,8, NOTE_A4,8,
  
  NOTE_B4,4, NOTE_C5,8, NOTE_B4,8, NOTE_A4,8, NOTE_G4,8,//6
  NOTE_FS4,4, NOTE_G4,8, NOTE_A4,8, NOTE_B4,8, NOTE_G4,8,
  NOTE_A4,-2,
  NOTE_D5,4, NOTE_G4,8, NOTE_A4,8, NOTE_B4,8, NOTE_C5,8, 
  NOTE_D5,4, NOTE_G4,4, NOTE_G4,4,
  NOTE_E5,4, NOTE_C5,8, NOTE_D5,8, NOTE_E5,8, NOTE_FS5,8,
  
  NOTE_G5,4, NOTE_G4,4, NOTE_G4,4,
  NOTE_C5,4, NOTE_D5,8, NOTE_C5,8, NOTE_B4,8, NOTE_A4,8, //12
  NOTE_B4,4, NOTE_C5,8, NOTE_B4,8, NOTE_A4,8, NOTE_G4,8,
  NOTE_A4,4, NOTE_B4,8, NOTE_A4,8, NOTE_G4,8, NOTE_FS4,8,
  NOTE_G4,-2,

 
};

int melody3[] = {

  // The Godfather theme
  // Score available at https://musescore.com/user/35463/scores/55160

  REST, 4, REST, 8, REST, 8, REST, 8, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, //1
  NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8, NOTE_G4, 8,
  NOTE_E4, 2, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8,
  NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_E4, 8, NOTE_DS4, 8,
  
  NOTE_D4, 2, NOTE_D4, 8, NOTE_F4, 8, NOTE_GS4, 8, //5
  NOTE_B4, 2, NOTE_D4, 8, NOTE_F4, 8, NOTE_GS4, 8,
  NOTE_A4, 2, NOTE_C4, 8, NOTE_C4, 8, NOTE_G4, 8, 
  NOTE_F4, 8, NOTE_E4, 8, NOTE_G4, 8, NOTE_F4, 8, NOTE_F4, 8, NOTE_E4, 8, NOTE_E4, 8, NOTE_GS4, 8,

  NOTE_A4, 2, REST,8, NOTE_A4, 8, NOTE_A4, 8, NOTE_GS4, 8, //9
  NOTE_G4, 2, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8, 
  NOTE_E4, 2, NOTE_E4, 8, NOTE_G4, 8, NOTE_E4, 8,
  NOTE_D4, 2, NOTE_D4, 8, NOTE_D4, 8, NOTE_F4, 8, NOTE_DS4, 8, 
   
  NOTE_E4, 2, REST, 8, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, //13

  //repeats from 2
  NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8, NOTE_G4, 8, //2
  NOTE_E4, 2, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8,
  NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_E4, 8, NOTE_DS4, 8,
  
  NOTE_D4, 2, NOTE_D4, 8, NOTE_F4, 8, NOTE_GS4, 8, //5
  NOTE_B4, 2, NOTE_D4, 8, NOTE_F4, 8, NOTE_GS4, 8,
  NOTE_A4, 2, NOTE_C4, 8, NOTE_C4, 8, NOTE_G4, 8, 
  NOTE_F4, 8, NOTE_E4, 8, NOTE_G4, 8, NOTE_F4, 8, NOTE_F4, 8, NOTE_E4, 8, NOTE_E4, 8, NOTE_GS4, 8,

  NOTE_A4, 2, REST,8, NOTE_A4, 8, NOTE_A4, 8, NOTE_GS4, 8, //9
  NOTE_G4, 2, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8, 
  NOTE_E4, 2, NOTE_E4, 8, NOTE_G4, 8, NOTE_E4, 8,
  NOTE_D4, 2, NOTE_D4, 8, NOTE_D4, 8, NOTE_F4, 8, NOTE_DS4, 8, 
   
  NOTE_E4, 2 //13
};

int notes = sizeof(melody) / sizeof(melody[0]) / 2;
int notes2 = sizeof(melody2) / sizeof(melody2[0]) / 2;
int notes3 = sizeof(melody3) / sizeof(melody3[0]) / 2;

// this calculates the duration of a whole note in ms
int wholenote = (60000 * 4) / tempo;
int wholenote2 = (60000 * 4) / tempo2;
int wholenote3 = (60000 * 4) / tempo3;

int divider = 0, noteDuration = 0;
int divider2 = 0, noteDuration2 = 0;
int divider3 = 0, noteDuration3 = 0;


void setup() {
  Serial.begin(9600);
   pinMode(led, OUTPUT);
  pinMode(buzzer1,OUTPUT);
  pinMode(buzzer2,OUTPUT);
  pinMode(vibrate,OUTPUT);
   }

   
void loop(){ 
//pressure sensor for heart
int pressRead2=analogRead(press2);


//  LED for heart
//  analogWrite(led, brightness);
// brightness = brightness + fadeAmount;
//  // reverse the direction of the fading at the ends of the fade:
//  if (brightness <= 0 || brightness >= 255) {
//    fadeAmount = -fadeAmount;
//  }
//  // wait for 30 milliseconds to see the dimming effect

//the vibration motor
  if(pressRead2>100){
//  brightness=255;
  for (int i =0;i<5;i++){
  digitalWrite(vibrate, HIGH);
  delay(300);
  digitalWrite(vibrate, LOW);
  delay(700);
}

//for buzzer

for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

    // calculates the duration of each note
    divider = melody[thisNote + 1];
    if (divider > 0) {
      // regular note, just proceed
      noteDuration = (wholenote) / divider;
    } else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5; // increases the duration in half for dotted notes
    }

    // we only play the note for 90% of the duration, leaving 10% as a pause
    tone(buzzer2, melody[thisNote], noteDuration * 0.9);

    // Wait for the specief duration before playing the next note.
    delay(noteDuration);

    // stop the waveform generation before the next note.
    noTone(buzzer2);
  }
    
  }




  
//  button&sensor for gloves
int pressRead=analogRead(press1);
int buttonRead=digitalRead(button);
/*
 if (buttonRead==HIGH) {
    first_click = true;
    lastDebounceTime = millis();
  } else if (millis() - endTime < interval) {

*/
//
////  debounce & button for gloves to produce sounds
//if(pressRead>10){
//  Serial.print(pressRead);
//  Serial.print("   ");
//  Serial.println(buttonRead);
//
//if(millis() - lastDebounceTime <= debounceDelay){ 
//if (buttonRead==HIGH){
// if( firstClick==false&&secondClick==false){
//  firstClick=true;
//    Serial.println("haha");
//    Serial.println(firstClick);
//}else if (firstClick==true&&secondClick==false){
// secondClick=true;
// Serial.println("why wrong");
//}}}}
//if(millis() - lastDebounceTime > debounceDelay){ 
//if (firstClick==true&&secondClick==false){
//  for (int thisNote2 = 0; thisNote2 < notes2 * 2; thisNote2 = thisNote2 + 2) {
//
//    // calculates the duration of each note
//    divider2 = melody2[thisNote2 + 1];
//    if (divider2 > 0) {
//      // regular note, just proceed
//      noteDuration2 = (wholenote2) / divider2;
//    } else if (divider2 < 0) {
//      // dotted notes2 are represented with negative durations!!
//      noteDuration2 = (wholenote2) / abs(divider2);
//      noteDuration2 *= 1.5; // increases the duration in half for dotted notes2
//    }
//
//    // we only play the note for 90% of the duration, leaving 10% as a pause
//    tone(buzzer1, melody2[thisNote2], noteDuration2 * 0.9);
//
//    // Wait for the specief duration before playing the next note.
//    delay(noteDuration2);
//
//    // stop the waveform generation before the next note.
//    noTone(buzzer1);
//  }
//    
//     lastDebounceTime = millis();
//     firstClick=false;
//     }
// else if  (firstClick==true&&secondClick==true) {
//
//  for (int thisNote3 = 0; thisNote3 < notes3 * 2; thisNote3 = thisNote3 + 2) {
//
//    // calculates the duration of each note
//    divider3 = melody3[thisNote3 + 1];
//    if (divider3 > 0) {
//      // regular note, just proceed
//      noteDuration3 = (wholenote3) / divider3;
//    } else if (divider3 < 0) {
//      // dotted notes3 are represented with negative durations!!
//      noteDuration3 = (wholenote3) / abs(divider3);
//      noteDuration3 *= 1.5; // increases the duration in half for dotted notes3
//    }
//
//    // we only play the note for 90% of the duration, leaving 10% as a pause
//    tone(buzzer1, melody3[thisNote3], noteDuration3 * 0.9);
//
//    // Wait for the specief duration before playing the next note.
//    delay(noteDuration3);
//
//    // stop the waveform generation before the next note.
//    noTone(buzzer1);
//  }
//      }
//  else if(firstClick==false&&secondClick==false){
//     lastDebounceTime = millis();
//    }
//
//
// 
//}
///*
////  ////the first song
//
//// ////the second song
// if (count%2==0&&count!=lastcount){
// }
//        tone(buzzer1,HIGH);
//        delay(50);
//        noTone(buzzer1);
//        delay(50);
//        tone(buzzer1,HIGH);
//        delay(50);
//        noTone(buzzer1);
//        delay(50);
//         tone(buzzer1,HIGH);
//        delay(50);
//        noTone(buzzer1);
//        delay(50);
//         tone(buzzer1,HIGH);
//        delay(50);
//        noTone(buzzer1);
//        delay(50);
//   }

//*/
//
//  lastButtonState=buttonRead;
//  delay(200);
//
//  lastcount=count;
//}
  }