Final Project (Prof. Rudi)

As for my final project for interaction lab, it is really a challenging but enjoyable process.

First, for the brainstorming part, since I had varicella and was at home at that time, I videoed chat with Amy about the ideas and the themes of our project. We originally wanted to make a transparent box with the same scene in processing and put some real flowers in it so that when people’s hand touches the specific flower, the flower in the screen moves the same route as it. But as we discussed, this is kind of a repetition of the scenes. So we changed our ideas into making a grassland with flowers on the screen by processing and the gears hold the real flowers, making a sense that when the user drags the flower out of the screen and the flower shows up in the reality.

The inspiration for our project comes from a famous sentence by Shelley “If winter comes, is spring still far behind.” And the theme of our project is to give people a feeling of the transformation from winter to spring. We want to first make a scene of winter and when the user blows on the screen, just like the wind of spring. Also, since now it is winter and it is cold outside, we are eager to a warmer environment. And there is another idea said by our Prof. Rudi, we are kind of limited in this academic building because we students and professors take shuttle bus or metro every day to go to school or work. In this way, people can not really connect with nature. So by our project, we want to give users a sense of the transformation from winter to spring, just like from cold to warmth.

So when I came back to Shanghai from home, Amy and I separated our work on the project. I focus more on the processing part, the scene setting part, and the physical decoration part.

At first, I want to set the winter scene with a picture of peaceful white snow and add some codes to make the falling snow pieces.

But then I found out that in that scene, it is difficult to realize the “transformation”. So I changed my idea to make a scene of melting an ice cube. One the user blows on the sound sensor, the video plays and it gives the user the sense that by their blow, the ice cube starts to melt and spring comes. So I searched lots of videos on YouTube.

and finally found a video of a melting ice cube. But since it is a real process of the melting of an ice cube, the video is quite long, which might lead to the user’s hurries. So I used the app called iMovie to accelerate the video and made it to about seven seconds. Then I chose the background music from the album of Bandari.

Another big problem that I faced is to naturally set the background and the flowers together. My original idea was to set a scene that is vivid and almost real to life. I even bought some fresh flowers on Taobao. But after I spent the whole afternoon load the images of different types of flowers to the big scene of a vivid grassland. I myself even found it really unnatural. And when I asked Amy and some other friends of mine, they all felt that the background and the flowers were kind of weird and it did not correspond to the painting style of this era. Since our project is made by high technology, I think it is better to make a cartoon scene.

So I looked through the pictures and remembered one of my favorite Japanese painter, Takashi Murakami. His sunflowers are quite famous and cute. I chose to use those flowers in the scene.

For the background, since I decided to create a cartoon scene, I first wanted to draw the gradient ramp myself by checking the RGB chart online. But later I found that I could not make the transition of each color as smooth as possible just by detecting by my eyes. So I chose to search for pictures online and combined them. Since some components such as sun, bees, and butterflies are with the white background of each picture, I used PhotoShop in our school’s Mac lab to delete the white background and made it embed into the scene of processing.

As for the coding part, we also used boolean to control the transformation of the scene of winter and spring. Coding, for me, is always the most difficult part of the project.

As Prof. Rudi suggested us that our different settings of our project are somehow not connected. So I used a box to hold the computer and stuck some pictures of the flowers to cover the box.

I know that our project has many things to improve, such as decorations and coding. It is actually a quite rough project and the sound sensor is exposed and it is kind of strange.

But the whole process is really enjoyable. I really enjoy the process of starting our project by ourselves and by many many efforts we finished it by ourselves. I am really grateful to my partner Amy that she wrote many difficult codes with a fever. I really also want to say thank you to Prof. Rudi. Thank you for all the knowledge that you have taught us and all the great suggestions. It’s such a pleasure to enroll in your class and have you as my first professor in the first semester of my college year. Thank you a lot!!!!

 

 

import processing.serial.*;

long lastH = 0;
Serial myPort;
int valueFromArduino;
import processing.video.*;
Movie myMovie;
PFont font;
int i=0; 
boolean istheresound=false;
boolean isfileplays=false;
//int count=200;
//float[] t=new float[count];
//float[] l=new float[count];
//float[] r=new float[count];
//float[] s=new float[count];

import processing.sound.*;
SoundFile filespring;
//SoundFile filewinter;
import de.voidplus.leapmotion.*;
float fingerThumbX, fingerThumbY, fingerIndexX, fingerIndexY, fingerMiddleX, fingerMiddleY, fingerRingX, fingerRingY, fingerPinkX, fingerPinkY;
PImage smallflower;
PImage smallflower1;
PImage smallerflower;
PImage flower;
PImage sun;
PImage bees;
PImage butterflies;
PImage clouds;
PImage grassland;
PImage meltingcubeimage;
float x=150; //left flower
float y=500;
float a=520; //middle flower
float b=550;
float c=1300; //right flower
float d=550;

color m;
float modifier;
Boolean grabbed = false;
Boolean grableft = false;
Boolean grabright = false;

// ======================================================
// Table of Contents:
// ├─ 1. Callbacks
// ├─ 2. Hand
// ├─ 3. Arms
// ├─ 4. Fingers
// ├─ 5. Bones
// ├─ 6. Tools
// └─ 7. Devices
// ======================================================

LeapMotion leap;


void setup () {
  fullScreen();
  background(255); 
  //size(1440, 700);
  //filewinter = new SoundFile(this, "Bandari - Hymn.mp3");

  filespring = new SoundFile(this, "Spring.mp3");
  myMovie = new Movie(this, "MeltingIceCube.mp4");

  smallflower=loadImage("smallsmallflower.png");
  flower=loadImage("smallflowernew.png");
  sun=loadImage("sunnew.png");
  bees=loadImage("beesnew-2.png");
  butterflies=loadImage("butterflies-2.png");
  smallerflower=loadImage("small*3flower.png");
  clouds=loadImage("clouds.jpg");
  grassland=loadImage("grassland.jpg");
  smallflower1=loadImage("smallsmallflower.png");
  meltingcubeimage=loadImage("meltingcubeimage.png");
  image(meltingcubeimage,0,0);
  leap = new LeapMotion(this);
  printArray(Serial.list());
  // this prints out the list of all available serial ports on your computer.

  myPort = new Serial(this, Serial.list()[ 2 ], 9600);
}
// 1. Callbacks

void leapOnInit() {
  // println("Leap Motion Init");
}
void leapOnConnect() {
  // println("Leap Motion Connect");
}
void leapOnFrame() {
  // println("Leap Motion Frame");
}
void leapOnDisconnect() {
  // println("Leap Motion Disconnect");
}
void leapOnExit() {
  // println("Leap Motion Exit");
}


void draw () {
  if (myMovie.available()) {
    myMovie.read();
  }

  //for(int i=0;i<count;i++){
  //if(l[i]>height){
  //l[i]=-5;
  //}
  //fill(255);
  //if(dist(mouseX,mouseY,t[i],l[i])<20){
  //l[i]=-5;
  //t[i]=random(0,width);
  //}
  //l[i]+=s[i];
  //noStroke();
  //ellipse(t[i],l[i],r[i],r[i]);
  //}

  while ( myPort.available() > 0) {
    valueFromArduino = myPort.read();
  }
  if (valueFromArduino > 25) {
    istheresound=true;
  }
  //println(valueFromArduino);
  if (istheresound==true) {
 




    noStroke();
    fill(#ADFF2F);

    beginShape(); //dark green
    fill(#548B54);
    vertex(0, height/1.22);
    vertex(width, height/1.2);
    vertex(width, height);
    vertex(0, height);
    endShape(CLOSE);
    imageMode(CORNER);

    image(clouds, 0, 0);
    imageMode(CENTER);
    image(grassland, width/2, height/1.307);

    strokeWeight(12);
    stroke(#0E500B); //left
    line(x, y, x, y+200);
    stroke(#000000); //middle
    line(a, b, a, b+180); 
    stroke(#4D0C10); //right
    line(c, d, c, d+130);


    image(smallflower, a, b); //middle
    image(flower, x, y); //left
    image(sun, 1200, 150);
    image(bees, width/2, height/2);
    image(butterflies, width/1.3, height/1.3);
    image(smallerflower, c, d); //right


    strokeWeight(15);
    // stroke(#556B2F);
    //line(x, y, x+55, y+242);

    strokeWeight(10);
    stroke(0);
    //m=get(mouseX, mouseY);
    fill(255, 0, 0);
    ellipse(fingerThumbX, fingerThumbY, 15, 15);
    ellipse(fingerIndexX, fingerIndexY, 15, 15);
    ellipse(fingerMiddleX, fingerMiddleY, 15, 15);
    ellipse(fingerRingX, fingerRingY, 15, 15);
    ellipse(fingerPinkX, fingerPinkY, 15, 15);



    m = get(int(fingerThumbX), int(fingerThumbY));


    myMovie.play();
    //println("movie current time: " + myMovie.time());

   

    updateleapmotion();

    if(b<400 ) {
      //OOlastH = millis();
      myPort.write('H');
      println("H1");
      b=-10000;
    } else {
      myPort.write('L');
    }
     if (y<300 ) {
      //lastH = millis();
      myPort.write('H');
      println("H2");
      y=-10000;
    } else {
      myPort.write('L');
    }
     if (d<300  && millis() - lastH > 1000) {
      lastH = millis();
      myPort.write('H');
      println("H3");
      d=10000;
    } else {
      myPort.write('L');
    }
    //println("the height of the flower" + b);
    if (myMovie.time() < myMovie.duration()) {
      pushStyle();
      imageMode(CORNER);
      image(myMovie, 0, 0, width, height);
      popStyle();
      if(isfileplays==false){
       filespring.play();
       isfileplays=true;
      }
    }
    //if (myMovie.time() > myMovie.duration()) {
     
    //  filewinter.stop();
    //}
  }
}

Assignment: Computer Vision (Prof. Rudi)

I choose Design & Architecture.

  • The reason why I choose it

I choose it mainly because it was really once my dream to be an architect. I really like designing buildings and indoor decorations. I am so excited that architecture can be related to our interactive media art and I want to figure out how.

  • How does it relate to my own experiences with Computer Vision

Actually, in my real life, I have seen many architectural scenes drawn by computer vision. For example, a few years ago my family wanted to move and visited many residential communities. Since those are new communities and were not completely constructed, we got to see the visual scene of the whole community and its surroundings either on an iPad or a 3D model. Another experience was that when I was surfing on an app called “weibo”, there was new technology that the picture can be showed in a panorama view of the beautiful scenery around the world, which leaves me a really deep impression.

  • The tools that I think are used

To pursue the 3D model of the scene of the building or the indoor scene of a room, I think there may be a software which can conduct the 3D drawing and show the structure of the building, just like the following picture.

By googling the source of the picture, I find a software which is from Russia. It is called the Visual Building Museum.

I also find a video describing the process of 3D modeling, which is conducted by the software 3DS. 3DS is a good and popular software used for 3D modeling. (I’m sad that the process was taught in Chinese.) The rectangles read that draw the 2D scene ➡️ modeling ➡️ choose materials ➡️ algorithm ➡️ synthesize the scene ➡️ Typesetting

  • The challenges that the developers may face

There is a disadvantage of the software 3Ds, which is that the time consumed of applying the texture or the color to the scene to make it more vivid is quite long. And to solve this problem, there is another software invented called “Vray”. It works by tracing the track of photon, thus speeding up the process of applying the texture and color, or even light sensation. This new technology remains to be discussed.

 

 

 

 

 

Lab 11: Media Controller (Prof. Rudi)

For today’s recitation, among many choices, I chose the vibration sensor. I wanted to create a scene when the user knocks on the vibration sensor and a perfect piece of glass will be broken. I actually got this idea from a game I had seen from the app store. It was tricky because it seemed like my iPhone screen was really broken.

I found two pictures of glass on the Internet. One of them is the perfect piece of glass and the other one is a broken piece. Just like the following.

Actually, in my midterm project with Amy, I have already searched online on how to upload images in processing. But this time there was something wrong with my processing and it read “syntax error … “. I asked Marcela and she helped me create a new sketch and it worked. We do know what’s wrong with the first sketch till now… And this process took me quite a long time and I did not finish my plan during the recitation. I returned the vibration sensor to Luis and borrowed another one from the equipment room.

I connected the circuit of the vibration sensor.

Actually, the result was not that satisfying and I asked a few fellows and they predicted the sensor was not that sensitive so that the broken glass was popping.

Arduino codes:

 

 

 

 

 

 

 

import processing.serial.*;


Serial myPort;
int valueFromArduino;

PImage img1;
PImage img2;
void setup() {
  size(1000, 900);
  img1 = loadImage("perfect glass.jpg");
  img2 = loadImage("broken glass.jpg");
  printArray(Serial.list());
  // this prints out the list of all available serial ports on your computer.
  
  myPort = new Serial(this, Serial.list()[ 8 ], 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.
}


void draw() {
  background(255);
  imageMode(CENTER);

// to read the value from the Arduino
  while ( myPort.available() > 0) {
    valueFromArduino = myPort.read();
  }
  if (valueFromArduino<15){
    image(img1, 500, 200);
    
}
if(valueFromArduino>15){
    image(img2, 500, 400);
}
}

Soldering (Prof. Rudi)

During today’s recitation, I chose to learn “soldering”. I chose it because it seemed like a new field to me and I’ve never tried that. Basically, soldering is to heat and melt a metal so as to stick together with other pieces of metal and when it cools down, the metal becomes hard again.

Here is the equipment provided.

First I learned that once use the “gun”, its pin must be shining. The above picture was not quite clear but the pin was indeed shiny! And then we were recommended to set the temperature to 400.

The first practice was to stick the wire to the tinfoil. As to sustain the wire and keep it stable on the table. I used tape to stick the rubber part on the table and put the metal pin onto the tinfoil. Then I held the metal wire in my left hand and held the gun in my right hand. As the metal melted the liquid flew onto the pin of the gun so that the gun stuck the pin of the wire onto the tinfoil. The first try was quite easy. The only one problem was that sometimes the melting wire also stuck to the tinfoil. Then Leon told me just put the gun on it and they indeed separated.

The second practice was to stick two wires together. First, I wrapped the two wires together physically and then used helping hands to hold them. And it was the same with the first practice and I stuck them together.

 

The third practice is to connect a circuit by soldering. First I combined LED and two wires with its legs. Then I connected the resister with either leg.

Then I used button battery to try whether the circuit was working. It did work! (I also learned that the cathode is on the edge of the button battery)

This recitation is fruitful and I hope I can use the techniques of soldering in my final project on decorating.

Fabrication Techniques in Final Project (Prof. Rudi)

Due to my sick leave, I lost the chance of experiencing the 3D printer. But Amy and I had some video calls during my sick leave and we have discussed about the fabrication techniques in our final project.

Basically, as we need the flowers rise up from the box, we may need to use gears to push the flower smoothly. So first, we decide to use fabrication techniques to print out a couple of gears. Then, we are considering printing out the flowers but this might not be practical so we need to try.

I really look forward to using fabrication techniques in my final project!

Interaction in Final Project (Prof. Rudi)

Interaction is defined in the dictionary as “an occasion when two or three people or things communicate with or react to each other”. The definition shows that once there is an interaction, there is more than one component included. And also, the components can not just stay still and do their own works, instead, there is a communication between them and there are feedbacks. The communication can be in words or in gestures, the only demand is that there is participation and no component is left alone.

And in my final project, Amy and I decided to make a scene where users blow a wind on the screen of the computer, the flowers bloom. And then when the user put his or her hand into a box to pick the flower in a specific color, there will be a flower rise up from the box in that color. I think in our final project there is a strong sense of interaction. First, as for blowing and the blooming of the flowers, it is an interaction between the user and the scene, which might be an area of a grassland. The action “blow” is computed by the user and then result in an action in the scene. And then there is another interaction when the user put the hand on the scene, the flower will come out as if the user actually pick the flower out of the scene. And I think for every project, the most difficult part is the interaction part. Because we need to make the scene natural. For instance, the hand in the scene of flowers might be odd. So we may use the leap motion to reflect the shadow of the hand on the screen instead of drawing it.

So to realize this interaction in our final project, there are a couple of things we need to pay attention to. First, the process of the flowers from close to blooming up. This part is important because it represents the theme of our project, which is the coming of spring. My idea is to draw a scene with the flowers close and another scene with the flowers blooming up. And write a “++” or “- -” function and let the coordinate gradually change from the one to another. And the second important part is to let the hand naturally embed into the scene. Amy and I have already searched some information online and decide to use leap motion. I don’t know how to use the leap motion yet, but I think it is super cool and it’s a great choice. And we want to use gears to rise up the flowers made of paper. And as for the flowers made of paper, I may either make them myself or buy some on Taobao, which depends on how good I make the flowers.

I know it is difficult to connect the scene on the screen and the scene inside the box together, so to reduce the distance between the user to the screen, we may use an iPad to replace the laptop. We will try our best the pursue our project.

Project tested (Professor: Rudi)

I tried Samantha’s project which is called the sound of the fish. 

The most interesting part I found about her project was the process if chasing the water drop. And I like the tinge of the project because I think it makes me feel comfortable. I also like the way that the water drops and the drops have cute tails. As for the beautification, I like the shell, it looks so vivid and the pearl within it is controlled by RGB LED. With the decoration of the cotton, we users can not even notice the wires and boards inside it. I think that is the point that my project should be improved.

One thing I find might be improved if the tones of the buzzers have a harmony atmosphere. Since now it is just high and low tones without a reference to a piano or other instruments. Another thing is that maybe changeable paths will be better.

Overall, I really like Samantha’s project very much!

Midterm Project: Gold Miner (Professor: Rudi)

Professor: Rudi

Midterm Project: Gold Miner

Partner: ZhangTao (Amy)

First, we found it hard to pop up ideas, so we limited our brainstorming time to five minutes to force ourselves to get ideas of the project. After brainstorming, there are two ideas that we found quite good which are doll-clipping machine and gold miner. But we realized that we might need to make a 3D scene for the doll-clipping machine, which might be difficult to make up. And also, most of Chinese have played gold miner before, however, we think just to press the key is not quite convenient for people to feel the pressure. So we decided to use pressure sensors. To make the game more fun, we roughly decided to make it a two-player battle game.

As we had already confirmed the project, last weekend I began to draw the scene of the game. I first separate two scenes and began with the old lovely miner. I strictly noted every component just beside the codes because I realized the codes might be quite long. And at the beginning, I set the background in dark yellow, which represented the underground. Then I found that the gold might also be yellow so I decided to change the background into blue, which represented the undersea. It took me an afternoon to find every coordinate and draw the miner.

I also drew a few bombs and wrote the codes that if the rope touches the bomb, the bomb will expand and the buzzer will ring.

I strictly noted every component just beside the codes because I realized the codes might be quite long. And at the beginning, I set the background in dark yellow, which represented the underground. Then I found that the gold might also be yellow so I decided to change the background into blue, which represented the undersea. It took me an afternoon to find every coordinate and draw the miner.

I used the “beginShape” function and drew golds in irregular shapes. And Amy wrote the function “get” to let the rope drag up the gold if it read the color of it. We worked separately and when we combined our codes together, we found that it is easy to use “get” to drag regular shapes like an ellipse but it is unable to drag the irregular shapes up because the irregular shapes don’t have a central point to move with. So my another plan was to cover the irregular shape with an ellipse as the label of the price. And the different price has a different color of the label so that the ball at the end of the rope could read different color and then drag.

Then, I found it would be better if I upload a real image of gold mine. I used PS to swipe the white edge of the image and us PImage to upload it. I set both image and ellipse mode to CENTER so that they could be dragged up together.

When I borrowed pressure sensors from the equipment room, I mistook the vibration sensors and didn’t know how to use them. When I asked professor Rudi, I found that vibration sensor was wrong from the beginning. And professor Rudi suggested that we should use acceleration sensor or FSR sensor. As a result, we chose FSR sensor.

#FSR#

We experienced a few problems with the FSR. First, as it is a battle game, I borrowed two FSR, however, one of them has two wires connected with it and the other one doesn’t. But we wanted to make the two players feel the same. So I exchanged the one with two wires to no wire. And I used two small breadboards to separate the two FSR.

I also learned the function “text” to text words in processing. And I put introductions on the screen.

As to make the pressure clearer for the player, we put the text “PRESSURE: ” +sensorValues[0] to embody the value of the FSR beside the player so that the player can see.

The rule of the game at first was to press the key to stretch and release the rope. When the ball at the end of the rope touches the gold then hold the key and pinch the FSR at the same time. After Thursday’s presentation, I asked Jack to try our game, and his feedback was it was kind of inconvenient to hold the key and pinch the FSR at the same time. He suggested that we should get rid of the key and just use the FSR. For instance, press the FSR to stretch and release the FSR to let the rope go back and wave again.

Then Amy and I tried the write the codes, but it turned out that we have checked for many times and also asked fellows to check and there were no mistakes in the codes. But when the rope went back, It stayed still and didn’t wave. So we changed the plan, we decided to use the boolean. And it eventually worked.

As to hide the wires and to beautify our project we use a small box to put Arduino board and breadboard in it. I cut the left and right sides to stretch the two small breadboards out. I stuck an NYU Shanghai paper on the box and made it a face and the two breadboards as hands.

selfie!                        

and our Arduino codes

After today’s recitation, we collected the suggestions. Most of the users suggested that the speed of the waving rope should be faster or the player needs to wait a long time. And professor Marcela suggested that we should also accelerate the speed of the rope going back and now it is not quite convenient to hold the sensor all the time.

I really enjoyed the process of making our gold miner. It took me almost a week to finish it and Amy and I gathered at the studio for two days till 9 pm. But I indeed learned many things by trying it myself, searching online and asking fellows and professors for advice. This is such a significant experience!

 

import processing.serial.*;

String myString = null;
Serial myPort;


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

int y = 200; //water distance from the top of the window
//x1,y1 is the coordinates of ball at the end of the left rope
//x2,y2 are the coordinates for the right rope
int x1=250;
int x2=750;
int speed1=1;
int speed2=1;
int y1=220;
int y2=220;

color m; //color detection left rope
color n; //color detection right rope

int ex1=200;//yellow label
int ey1=390;
int a = 200; //yellow gold
int c = 400;
int moneyleft = 0;
int moneyright = 0;
int ex2 = 700;//orange label
int ey2 = 590;
int ex3 = 350;//green label
int ey3 = 690; 
int ex4 = 1100;//purple label
int ey4 = 490;
int ex5 = 400; //pink label
int ey5 = 440;
int d = 700; //orange gold
int e = 600;
int f = 350; //green gold
int g = 700;
int h = 1100;  //purple gold
int i = 500;
int j = 400; //pink gold
int k = 450;

boolean zeroed = false;
boolean zeroed1 = false;

void setup() {
  size(1200, 1000);

  setupSerial();
}
void draw() {
  //Start of rendering code
  background(255);

  beginShape(); //shallow blue
  fill(#39C8E0);
  noStroke();
  vertex(0, 200);
  vertex(1200, 200);
  vertex(1200, 400);
  vertex(0, 550);
  endShape(CLOSE);

  beginShape (); //middle blue
  fill(#39BAE0);
  noStroke();
  vertex(0, 550);
  vertex(1200, 400);
  vertex(1200, 700);
  vertex(0, 700);
  endShape(CLOSE);

  beginShape(); //dark blue
  fill(#39AAE0);
  noStroke();
  vertex(0, 700);
  vertex(1200, 700);
  vertex(1200, 1000);
  vertex(0, 1000);
  endShape(CLOSE);

  beginShape(); //platform
  fill(#906B14);
  vertex(220, 200);
  vertex(230, 180);
  vertex(440, 180);
  vertex(450, 200);
  endShape();

  beginShape(); //platform
  fill(#906B14);
  vertex(720, 200);
  vertex(730, 180);
  vertex(940, 180);
  vertex(950, 200);
  endShape();

  PImage img;

  img = loadImage("gold .png");
  imageMode(CENTER);
  image(img, a, c);

  PImage img1;

  img1 = loadImage("gold .png");
  imageMode(CENTER);
  image(img1, d, e); 

  PImage img2;

  img2 = loadImage("gold .png");
  imageMode(CENTER);
  image(img2, f, g); 

  PImage img3;

  img3 = loadImage("gold .png");
  imageMode(CENTER);
  image(img3, h, i); 

  PImage img4;

  img4 = loadImage("gold .png");
  imageMode(CENTER);
  image(img4, j, k); 



  stroke(0);
  line(300, 130, x1, y1);//line left
  line(800, 130, x2, y2);//line right

  fill(0);
  ellipse(x1, y1, 20, 20);//left ball
  ellipse(x2, y2, 20, 20);//right ball
  x1=x1+speed1;
  x2=x2+speed2;

  fill(#FAD065); //yellow
  strokeWeight(1);
  ellipse(ex1, ey1, 90, 120);

  fill(#FA985B); //orange
  ellipse(ex2, ey2, 90, 120);

  fill(#A3F79D); //green
  ellipse(ex3, ey3, 90, 120);

  fill(#9D9FF7); //purple
  ellipse(ex4, ey4, 90, 120);

  fill(#DF8FF0); //pink
  ellipse(ex5, ey5, 90, 120);

  fill(#010105);
  stroke(255, 0, 0);
  ellipse(800, 350, 50, 50); //bomb1
  ellipse(600, 700, 50, 50); //bomb2
  ellipse(100, 600, 50, 50); //bomb3
  ellipse(620, 500, 50, 50); //bomb4
  stroke(255, 0, 0);
  strokeWeight(3);
  line(790, 340, 810, 360); //bomb1
  line(790, 360, 810, 340); //bomb1
  line(590, 710, 610, 690); //bomb2
  line(590, 690, 610, 710); //bomb2
  line(90, 590, 110, 610); //bomb3
  line(110, 590, 90, 610); //bomb3
  line(610, 490, 630, 510); //bomb4
  line(610, 510, 630, 490); //bomb4
  //End of rendering code

  //get color values at ends of the lines
  m = get(x1, y1);
  n = get(x2, y2);


  if ( sensorValues[1] > 8 ) {
    speed1=0;
    zeroed = false;
    if (x1>300) {
      x1=x1+1;
    }
    if (x1<300) {
      x1=x1-1;
    }
    y1=y1+2;
  }
  
  if (sensorValues[1]<8) {
    if( zeroed == false){
      x1=300;
      y1=220;
      speed1 = 1;
      x1=x1+speed1;
      zeroed = true;
    }
  }
 
  
  
  //Wave the lines
  if (x1<100||x1>600) {
    speed1=speed1*-1;
  }
  if (x2<600||x2>1100) {
    speed2=speed2*-1;
  }//move the balls(hook)

 if ( sensorValues[0] > 8 ) {
    speed2=0;
    zeroed1 = false;
    if (x2>800) {
      x2=x2+1;
    }
    if (x2<800) {
      x2=x2-1;
    }
    y2=y2+2;
  }
  
  if (sensorValues[0]<8) {
    if( zeroed1 == false){
      x2=800;
      y2=220;
      speed2 = 1;
      x2=x2+speed2;
      zeroed1 = true;
    }
  }
  

  
  
  //stretch the line
  /*if (keyPressed) {
    if (key=='z') {
      speed1=0;//press 'z' to stop the ball

      if (x1>300) {
        x1=x1+1;
      }
      if (x1<300) {
        x1=x1-1;
      }
      y1=y1+2;
    }
    if (key=='x') {
      //x1=x1+speed1;
      //if (x1>300) {
      //  x1 = 399;
      //}
      //if (x1<300) {
      //  x1=101;
      //}
      x1 = 300;
      speed1=1;
      y1=220;
    }//restore the line
*/
    //start money detection
    if (sensorValues[1]>20 && m==#FAD065) {
      a=x1;
      c=y1;
      ex1=x1;
      ey1=y1;
      if (x1>300) {
        x1=x1-2;
        y1=y1-3;
      }
      if (x1<=300) {
        x1=x1+2;
        y1=y1-3;
      }
    }
    if (sensorValues[1]>30&&m==#FA985B) {
      d=x1;
      e=y1;
      ex2=x1;
      ey2=y1;
      if (x1>300) {
        x1=x1-2;
        y1=y1-3;
      }
      if (x1<=300) {
        x1=x1+2;
        y1=y1-3;
      }
    }
    if (sensorValues[1]>50&&m==#A3F79D) {
      f=x1;
      g=y1;
      ex3=x1;
      ey3=y1;
      if (x1>300) {
        x1=x1-2;
        y1=y1-3;
      }
      if (x1<=300) {
        x1=x1+2;
        y1=y1-3;
      }
    }
    if (sensorValues[1]>30&&m==#9D9FF7) {
      h=x1;
      i=y1;
      ex4=x1;
      ey4=y1;
      if (x1>300) {
        x1=x1-2;
        y1=y1-3;
      }
      if (x1<=300) {
        x1=x1+2;
        y1=y1-3;
      }
    }
    if (sensorValues[1]>35&&m==#DF8FF0) {
      j=x1;
      k=y1;
      ex5=x1;
      ey5=y1;
      if (x1>300) {
        x1=x1-2;
        y1=y1-3;
      }
      if (x1<=300) {
        x1=x1+2;
        y1=y1-3;
      }
    }
    //end money detection

    //Left bomb detection
    if (m==#010105) {
      ellipse(800, 350, 50+random(0, 20), 50+random(0, 20));
      ellipse(600, 700, 50+random(0, 20), 50+random(0, 20));
      ellipse(100, 600, 50+random(0, 20), 50+random(0, 20));
      ellipse(620, 500, 50+random(0, 20), 50+random(0, 20));
      myPort.write('H');
    } else if (m!=#010105) {
      myPort.write('L');
    }// read the color and drag it up

    if (a==300||c==150) {
      a=-10000;
      c=-10000;
      ex1=-100000;
      ey1=-100000;
      moneyleft=moneyleft+100;
    }// get the gold mine*/
    if (d==320||e==150) {
      d=-10000;
      e=-10000;
      ex2=-100000;
      ey2=-100000;
      moneyleft=moneyleft+200;
    }
    if (f==300||g==150) {
      f=-10000;
      g=-10000;
      ex3=-100000;
      ey3=-100000;
      moneyleft=moneyleft+100;
    }
    if (h==300||i==150) {
      h=-10000;
      i=-10000;
      ex4=-100000;
      ey4=-100000;
      moneyleft=moneyleft+150;
    }
    if (j==320||k==150) {
      j=-10000;
      k=-10000;
      ex5=-100000;
      ey5=-100000;
      moneyleft=moneyleft+150;
    }






/*
    if (key=='m') {
      speed2=0;
      y2=y2+1;
      if (x2>800) {
        x2=x2+1;
      }
      if (x2<800) {
        x2=x2-1;
      }
    }
  

  if (key=='n') {
    //x2=x2+speed2;
    //if (x2>800) {
    //  x2= 899;
    //}
    //if (x2<800) {
    //  x2=601;
    //}
    x2 = 800;
    speed2=1;
    y2=220;
  }
  */
  if (sensorValues[0]>20&&n==#FAD065) {
    a=x2;
    c=y2;
    ex1=x2;
    ey1=y2;
    if (x2>800) {
      x1=x1-2;
      y1=y1-3;
    }
    if (x2<=800) {
      x2=x2+2;
      y2=y2-3;
    }
  }
  if (sensorValues[0]>30&&n==#FA985B) {
    d=x2;
    e=y2;
    ex2=x2;
    ey2=y2;
    if (x2>800) {
      x2=x2-2;
      y2=y2-3;
    }
    if (x1<=800) {
      x2=x2+2;
      y2=y2-3;
    }
  }
  if (sensorValues[0]>50&&n==#A3F79D) {
    f=x2;
    g=y2;
    ex3=x2;
    ey3=y2;
    if (x2>800) {
      x2=x2-2;
      y2=y2-3;
    }
    if (x2<=800) {
      x2=x2+2;
      y2=y2-3;
    }
  }
  if (sensorValues[0]>30&&n==#9D9FF7) {
    h=x2;
    i=y2;
    ex4=x2;
    ey4=y2;
    if (x2>800) {
      x2=x2-2;
      y2=y2-3;
    }
    if (x2<=800) {
      x2=x2+2;
      y2=y2-3;
    }
  }
  if (sensorValues[0]>30&&n==#DF8FF0) {
    j=x2;
    k=y2;
    ex5=x2;
    ey5=y2;
    if (x2>800) {
      x2=x2-2;
      y2=y2-3;
    }
    if (x2<=800) {
      x2=x2+2;
      y2=y2-3;
    }
  }
  if (n==#010105) {
    ellipse(800, 350, 50+random(0, 20), 50+random(0, 20));
    ellipse(600, 700, 50+random(0, 20), 50+random(0, 20));
    ellipse(100, 600, 50+random(0, 20), 50+random(0, 20));
    ellipse(620, 500, 50+random(0, 20), 50+random(0, 20));
    myPort.write('H');
  } else if (n!=#010105) {
    myPort.write('L');
  }
  if (a==800||c==150) {
    a=-10000;
    c=-10000;
    ex1=-100000;
    ey1=-100000;
    moneyright=moneyright+100;
  }// get the gold mine*/
  if (d==800||e==150) {
    d=-10000;
    e=-10000;
    ex2=-100000;
    ey2=-100000;
    moneyright=moneyright+200;
  }
  if (f==800||g==150) {
    f=-10000;
    g=-10000;
    ex3=-100000;
    ey3=-100000;
    moneyright=moneyright+100;
  }
  if (h==800||i<150) {
    h=100000;
    i=1000000;
    ex4=100000;
    ey4=100000;
    moneyright=moneyright+150;
  }
  if (j==800||k==150) {
    j=-10000;
    k=-10000;
    ex5=-100000;
    ey5=-100000;
    moneyright=moneyright+150;
  }



  println("key " + key + ", x1: " + x1 + ", x2: " + x2);

  noStroke(); //color of face
  fill(#FFEFD5);
  beginShape();
  vertex(293, 25);
  vertex(293, 60);
  vertex(355, 57);
  vertex(355, 25);
  endShape();


  fill(0);
  noStroke();
  ellipse(300, 40, 5, 7);  //left eye
  ellipse(325, 41, 6, 8);  //right eye
  fill(#FFEFD5);

  stroke(0);
  strokeWeight(2);
  arc(305, 60, 30, 20, radians(330), radians(600), OPEN);  //nose
  arc(353.5, 41, 10, 20, radians(300), radians(430), OPEN); 
  arc(335, 50, 40, 20, radians(0), radians(165), OPEN);  //right face
  arc(295, 38, 10, 30, radians(110), radians(240), OPEN); //left face
  arc(320, 32, 70, 20, radians(215), radians(360), OPEN); //fajixian
  arc(365, 39, 15, 25, radians(200), radians(460), OPEN); //right ear
  arc(365, 40, 5, 7, radians(180), radians(270), OPEN); //right ear
  arc(320, 68, 30, 20, radians(30), radians(100), OPEN); //mouse

  fill(255);
  stroke(0);
  strokeWeight(2);
  fill(#C6C6C6);
  arc(298, 33, 9, 7, radians(180), radians(290), OPEN); //left eyebow
  arc(330, 33, 15, 6, radians(240), radians(360), OPEN); //right eyebow
  arc(280, 27, 20, 10, radians(210), radians(350), OPEN); //hair line
  arc(290, 22, 30, 10, radians(175), radians(310), OPEN); //hair line
  arc(300, 16, 60, 30, radians(230), radians(350), OPEN); //hair line
  arc(280, 15, 36, 20, radians(260), radians(360), OPEN); //hair line
  arc(316.5, 11, 30, 20, radians(320), radians(380), OPEN); //hair line
  arc(338, 20, 50, 30, radians(250), radians(360), OPEN); //hair line
  arc(292, 75, 20, 40, radians(100), radians(260), OPEN); //left beard
  arc(355, 74, 30, 50, radians(290), radians(450), OPEN); //right beard
  stroke(0);
  line(270, 95, 330, 95);
  line(270, 130, 330, 130);
  noFill();
  arc(273, 113, 20, 35, radians(90), radians(270), OPEN); //left wheel
  arc(343, 113, 23, 40, radians(0), radians(360));  //right wheel
  arc(269, 113, 23, 40, radians(90), radians(270), OPEN); //left
  arc(335, 113, 23, 40, radians(90), radians(270), OPEN); //right wheel
  line(331, 93, 340, 93); //right up
  line(331, 133, 340, 133); //right down
  line(258, 93, 265, 93); //left up
  line(258, 133, 268, 133); //left down
  arc(260, 113, 23, 40, radians(90), radians(270), OPEN); //leftest
  arc(360, 164, 80, 180, radians(180), radians(200), OPEN); //left leg
  line(320, 165, 355, 160); //left leg
  arc(340, 175, 40, 30, radians(180), radians(225), OPEN); //left shoe
  line(320, 175, 355, 173); //left shoe


  beginShape(); //left holder
  fill(#C9C6C1);
  vertex(252, 130);
  vertex(240, 150);
  vertex(240, 190);
  vertex(246, 190);
  vertex(246, 150);
  vertex(254, 133);
  endShape();
  beginShape(); //right holder
  fill(#C9C6C1);
  vertex(348, 124);
  vertex(360, 145);
  vertex(360, 190);
  vertex(354, 190);
  vertex(354, 147);
  vertex(344, 125);
  endShape(CLOSE);


  beginShape(); //handle
  fill(#D1C7AF);
  vertex(345, 110);
  vertex(364, 110);
  vertex(370, 95);
  vertex(375, 95);
  vertex(369, 114);
  vertex(345, 114);
  endShape(CLOSE);
  noFill();
  arc(375, 85, 100, 60, radians(260), radians(330)); //right arm
  arc(411, 78, 20, 30, radians(330), radians(370)); //right arm
  arc(400, 80, 40, 20, radians(10), radians(90)); //right arm
  line(370, 75, 385, 80); //right arm
  arc(400, 90, 40, 30, radians(200), radians(250)); //right arm
  arc(385, 100, 40, 30, radians(260), radians(320)); //right arm
  arc(380, 103, 40, 30, radians(270), radians(320)); //right arm
  fill(#FFEFD5);
  arc(380, 100, 20, 20, radians(140), radians(265)); //right hand
  arc(376, 102, 10, 10, radians(50), radians(140)); //right hand
  arc(383, 103, 10, 10, radians(50), radians(140)); //right hand
  arc(390, 104, 10, 10, radians(50), radians(140)); //right hand
  noFill();
  arc(404, 101, 20, 20, radians(145), radians(260));
  beginShape(); // right handle
  fill(#F5782F);
  vertex(395, 95);
  vertex(405, 95);
  vertex(405, 102);
  vertex(394, 102);
  endShape();
  noFill();
  arc(390, 110, 40, 55, radians(315), radians(380)); //clothes
  arc(380, 107, 80, 40, radians(43), radians(130)); //clothes
  arc(407, 123, 10, 10, radians(300), radians(430)); //clothes&trousers
  arc(435, 127, 50, 50, radians(140), radians(180)); //trousers
  arc(373, 170, 100, 100, radians(320), radians(360)); //trousers
  arc(370, 120, 100, 50, radians(80), radians(100)); //middle trousers
  arc(400, 125, 50, 100, radians(120), radians(160)); //right trousers
  arc(395, 175, 20, 30, radians(170), radians(210)); //end trousers
  line(387, 176, 422, 170);
  arc(402, 186, 40, 30, radians(173), radians(225)); //right shoe
  line(382, 187, 422, 184); //right shoe
  arc(414, 180, 20, 30, radians(330), radians(370)); //right shoe
  beginShape(); //right shoe
  fill(255);
  vertex(383, 189);
  vertex(383, 193);
  vertex(423, 190);
  vertex(423, 186);
  endShape();
  beginShape();
  fill(255);
  vertex(320, 175);
  vertex(323, 180);
  vertex(353, 180);
  endShape();


  fill(0);
  textSize(20);
  text("RMB 100", a-42, c);

  textSize(20);
  text("RMB 200", d-42, e);

  textSize(20);
  text("RMB 300", f-42, g);

  textSize(20);
  text("RMB 150", h-42, i);

  textSize(20);
  text("RMB 150", j-42, k);

  textSize(20);
  text("PLAYER 1:", 60, 50);

  /*textSize(20);
  text("1. Press z to stretch", 10, 80);

  textSize(20);
  text("2. Press x to restore", 10, 110);
*/

  textSize(20);
  text("PLAYER 2:", 1000, 50);
 
/*
  textSize(20);
  text("1. Press m to stretch", 950, 80);

  textSize(20);
  text("2. Press n to restore", 950, 110);
*/
  textSize(20);
  fill(255, 0, 0);
  text("!!You must use the proper pressure !!", 410, 40);

  textSize(20);
  text("!!Goal: 450 RMB!!", 490, 90);
 text(" pinch the hand to stretch the rope ", 410, 140);

  fill(0);
  textSize(20);
  text("MONEY:  "+moneyleft, 50, 160);
  text("PRESSURE: "+sensorValues[1], 50, 190);
  textSize(20);
  text("MONEY:  "+moneyright, 1000, 160);
  text("PRESSURE: "+sensorValues[0], 1000, 190);



  noStroke(); //color of face
  fill(#FFEFD5);
  beginShape();
  vertex(793, 25);

  vertex(793, 60);
  vertex(855, 57);
  vertex(855, 25);
  endShape();

  //right old guy
  fill(0);
  noStroke();
  ellipse(800, 40, 5, 7);  //left eye
  ellipse(825, 41, 6, 8);  //right eye
  fill(#FFEFD5);
  stroke(0);
  strokeWeight(2);
  arc(805, 60, 30, 20, radians(330), radians(600), OPEN);  //nose
  arc(853.5, 41, 10, 20, radians(300), radians(430), OPEN); 
  arc(835, 50, 40, 20, radians(0), radians(165), OPEN);  //right face
  arc(795, 38, 10, 30, radians(110), radians(240), OPEN); //left face
  arc(820, 32, 70, 20, radians(215), radians(360), OPEN); //fajixian
  arc(865, 39, 15, 25, radians(200), radians(460), OPEN); //right ear
  arc(865, 40, 5, 7, radians(180), radians(270), OPEN); //right ear
  arc(820, 68, 30, 20, radians(30), radians(100), OPEN); //mouse
  fill(255);
  stroke(0);
  strokeWeight(2);
  fill(#C6C6C6);
  arc(798, 33, 9, 7, radians(180), radians(290), OPEN); //left eyebow
  arc(830, 33, 15, 6, radians(240), radians(360), OPEN); //right eyebow
  arc(780, 27, 20, 10, radians(210), radians(350), OPEN); //hair line
  arc(790, 22, 30, 10, radians(175), radians(310), OPEN); //hair line
  arc(800, 16, 60, 30, radians(230), radians(350), OPEN); //hair line
  arc(780, 15, 36, 20, radians(260), radians(360), OPEN); //hair line
  arc(816.5, 11, 30, 20, radians(320), radians(380), OPEN); //hair line
  arc(838, 20, 50, 30, radians(250), radians(360), OPEN); //hair line
  arc(792, 75, 20, 40, radians(100), radians(260), OPEN); //left beard
  arc(855, 74, 30, 50, radians(290), radians(450), OPEN); //right beard
  stroke(0);
  line(770, 95, 830, 95);
  line(770, 130, 830, 130);
  noFill();
  arc(773, 113, 20, 35, radians(90), radians(270), OPEN); //left wheel
  arc(843, 113, 23, 40, radians(0), radians(360));  //right wheel
  arc(769, 113, 23, 40, radians(90), radians(270), OPEN); //left
  arc(835, 113, 23, 40, radians(90), radians(270), OPEN); //right wheel
  line(831, 93, 840, 93); //right up
  line(831, 133, 840, 133); //right down
  line(758, 93, 765, 93); //left up
  line(758, 133, 768, 133); //left down
  arc(760, 113, 23, 40, radians(90), radians(270), OPEN); //leftest
  arc(860, 164, 80, 180, radians(180), radians(200), OPEN); //left leg
  line(820, 165, 855, 160); //left leg
  arc(840, 175, 40, 30, radians(180), radians(225), OPEN); //left shoe
  line(820, 175, 855, 173); //left shoe


  beginShape(); //left holder
  fill(#C9C6C1);
  vertex(752, 130);
  vertex(740, 150);
  vertex(740, 190);
  vertex(746, 190);
  vertex(746, 150);
  vertex(754, 133);
  endShape();
  beginShape(); //right holder
  fill(#C9C6C1);
  vertex(848, 124);
  vertex(860, 145);
  vertex(860, 190);
  vertex(854, 190);
  vertex(854, 147);
  vertex(844, 125);
  endShape(CLOSE);


  beginShape(); //handle
  fill(#D1C7AF);
  vertex(845, 110);
  vertex(864, 110);
  vertex(870, 95);
  vertex(875, 95);
  vertex(869, 114);
  vertex(845, 114);
  endShape(CLOSE);
  noFill();
  arc(875, 85, 100, 60, radians(260), radians(330)); //right arm
  arc(911, 78, 20, 30, radians(330), radians(370)); //right arm
  arc(900, 80, 40, 20, radians(10), radians(90)); //right arm
  line(870, 75, 885, 80); //right arm
  arc(900, 90, 40, 30, radians(200), radians(250)); //right arm
  arc(885, 100, 40, 30, radians(260), radians(320)); //right arm
  arc(880, 103, 40, 30, radians(270), radians(320)); //right arm
  fill(#FFEFD5);
  arc(880, 100, 20, 20, radians(140), radians(265)); //right hand
  arc(876, 102, 10, 10, radians(50), radians(140)); //right hand
  arc(883, 103, 10, 10, radians(50), radians(140)); //right hand
  arc(890, 104, 10, 10, radians(50), radians(140)); //right hand
  noFill();
  arc(904, 101, 20, 20, radians(145), radians(260));
  beginShape(); // right handle
  fill(#F5782F);
  vertex(895, 95);
  vertex(905, 95);
  vertex(905, 102);
  vertex(894, 102);
  endShape();
  noFill();
  arc(890, 110, 40, 55, radians(315), radians(380)); //clothes
  arc(880, 107, 80, 40, radians(43), radians(130)); //clothes
  arc(907, 123, 10, 10, radians(300), radians(430)); //clothes&trousers
  arc(935, 127, 50, 50, radians(140), radians(180)); //trousers
  arc(873, 170, 100, 100, radians(320), radians(360)); //trousers
  arc(870, 120, 100, 50, radians(80), radians(100)); //middle trousers
  arc(900, 125, 50, 100, radians(120), radians(160)); //right trousers
  arc(895, 175, 20, 30, radians(170), radians(210)); //end trousers
  line(887, 176, 922, 170);
  arc(902, 186, 40, 30, radians(173), radians(225)); //right shoe
  line(882, 187, 922, 184); //right shoe
  arc(914, 180, 20, 30, radians(330), radians(370)); //right shoe
  beginShape(); //right shoe
  fill(255);
  vertex(883, 189);
  vertex(883, 193);
  vertex(923, 190);
  vertex(923, 186);
  endShape();
  beginShape();
  fill(255);
  vertex(820, 175);
  vertex(823, 180);
  vertex(853, 180);
  endShape();

  if (moneyleft>=450||moneyright>=450) {
    background(0);
    fill(255);
    textSize(30);
    text("Loser, choose a number from 1-5 and press it on the keyboard!", 250, 380);
    textSize(30);
    text("GAME OVER", 470, 300);
    if (keyPressed) {
      if (key=='1') {
        textSize(20);
        text("Sing a Song", width/2, height/2);
      }
      if (key=='2') {
        textSize(20);
        text("take an ugly selfie ", width/2, height/2);
      }
      if (key=='3') {
        textSize(20);
        text("GOOD LUCK! You are safe!", width/2, height/2);
      }
      if (key=='4') {
        textSize(20);
        text("turn around five times", width/2, height/2);
      }
      if (key=='5') {
        textSize(20);
        text("Scream!!!", width/2, height/2);
      }
    }
  }
  /* if(moneyright>400){
   background(0);
   fill(255);
   textSize(20);
   text("Loser, choose a number from 1-5 and press it on the keyboard!",400,400);
   if(keyPressed){
   if(key=='1'){
   textSize(20);
   text("Sing a Song", width/2,height/2);
   }
   if (key=='2'){
   textSize(20);
   text("take an ugly selfie ",width/2,height/2);
   }
   if(key=='3'){
   textSize(20);
   text("GOOD LUCK! You are safe!",width/2,height/2);
   }
   if(key=='4'){
   textSize(20);
   text("turn around five times", width/2,height/2);
   }
   if(key=='5'){
   textSize(20);
   text("Scream!!!",width/2,height/2);
   }
   }
   }
   */

  updateSerial();
  printArray(sensorValues);
}






void setupSerial() {
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[ 3 ], 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];
}
void updateSerial() {
  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) {
        for (int i=0; i<serialInArray.length; i++) {
          sensorValues[i] = int(serialInArray[i]);
        }
      }
    }
  }
}

Storyboard (Professor:Rudi)

Midterm Project Name: Gold Miner

Partner: Amy (Tao Zhang)

Professor: Rudi

 

 

Introductions:

1. This is a two-people battle game and there is a time limit

2. The hook automatically rotates, you can press your mouse to decide the direction of the hook to get the gold

3. The person who gets more money with the time limit is the winner

4. The power should be chosen properly, or the gold will not be lifted up

5. DIAMONDS are of high value!

6. The value of the gold depends on its size

7. Stones are useless

8. If you catch a bomb, the buzzer will ring and there will be two seconds when you can not move your hook

9. If you lose the game, there are random SURPRISES for you! 🙂

 

Lab 6: Serial Communication (Professor: Rudi)

Instructor: Rudi

Date: 2017/10/20

Today we aim at combining Arduino and Processing together.

First, I tried Processing to Arduino. I chose to work with the buzzer. 

First, I imitated the form which was provided in the portfolio. As for Arduino, since I wanted to work with the buzzer, I changed the “ledPin” into “buzzer”. And I replaced “HIGH” and “LOW” by 1000 and 500. I did the codes right but there always appeared a sign indicating something wrong with my Arduino. Then I asked Louis and he told me everything was good but I need to operate the Arduino first and then Processing. I tried as he said. There was nothing wrong showed but the system still didn’t work. I asked Jiwon and found out that I got the port index wrong. Then it worked. There was somehow something wrong with my buzzer so the volume was quite small. So I borrowed Amy’s buzzer to record a video.

Then I tried Arduino to Processing. I chose to play with the 10k potentiometer. Actually, we had learned it in Thursday’s class. It worked quite well.

I wanted to make the circle move randomly in every direction. Samantha and I shared the question. And then Marcela told us that we need to potentiometers to do so and we would learn how to do it soon.

It was fun! 🙂