Antonius: Final Project: Ghost Hunter

Final Project: Ghost Hunter

Date: May 18th

Instructor: Antonius

Aim:  Make a project that incorporate processing and Arduino in it.

Material: Processing, Arduino, Arduino kit, conductive tape, sponge, sponge mat, toy sword, accelerometer, wires.

Process:

  1. Designing: As I mentioned in my final project essay, I planned to make an interactive game. The user can control the moving of the character in the game by stepping on different part on the mat. The user can also kill enemies in the game by swing the actual sword. Initially I also designed a shield that the user can activate to block the attack from the enemies, but due to time limit and it might be too complicate for the plays to control so many controllers, I abandoned this part.
  2. Making the game:

I started by making the game in Processing first. Instead of using actual physical input, I use keyboard input first when building the game. The game is consisted of two components, the player and the enemies. I used the function keyPressed to control the character to move in four direction, by pressing the four keys “w”, “a”, “s”, “d”.

When making the enemies, at first I created them to let them chase the character. One problem with it is that all the enemies would overlap with each other after following the character for some time. To deal with this problem I tried several approaches, like detecting the distance between each enemy, but failed. In the end, I decided to let the enemies run randomly and let the character to catch them.

The enemies were made using object in processing. I defined all the characteristics for the enemies in a separate class, including color, position, speed, behavior after running into the character, etc. Then I use array list to call the enemies. In that case, each enemy could behave on their own, and when they are supposed to be killed, I could simply remove them from the list.

  1. Creating the input structure

As I mentioned in my design, I planned to let users to use their body movements to control the action of the character. The moving of the character was designed to be controlled by stepping on a stepping board on the ground. To control the character to move un, down, left and right, the players have to step on the front, back, left, right panels on the board. Originally I decided to use force sensor to be the information input, but considering that stepping might cause breaking the force sensor, I changed my mind to use soft button as input. With the help from professor Antonius, I was able to make my own soft button. Two conductive materials slicked on two separated boards, a sponge with a hole in it was used to connect the two boards. In this way, when stepping on the board, the conductive materials will get connected from the hole in the sponge, forming a whole loop that conducts current, which used to send input information to Arduino.

IMG_1599

The next step is to control the attack effect of the character. I used the accelerometer as input. When the user is swing the sword, the change in acceleration will be sensed and send to processing to trigger an “attack zone” around the character. And when the enemies overlapping with the “attack zone”, they will be eliminated.

IMG_1634

  1. Improving gaming experience

To make my game more playable, I add a time limit to the game. If the player can kill all the enemies in the limiting time, a screen showing “you win” will pop out; and if the enemies are not all killed in the time limit, a screen showing “game over” will pop out. What’s more to make the game more responsive, I also added sound effect when the enemies bounced against the character, and a sword swing effect when the user is swing the sword.

The pictures and actual effects are shown below.

IMG_1633

IMG_1635

IMG_1639

IMG_1637

//This is the processing code
import processing.serial.*;
Serial myPort;
int valA, valB, valC, valD;

ArrayList<Car> cars;
int x, y;
int x1, y1, a1, b1;


void setup() {
  myPort = new Serial(this, Serial.list()[2], 9600);
  size(720, 540);
  x = width/2;
  y = height/2;
  rectMode(CENTER);

  cars = new ArrayList<Car>();
  for (int i = 0; i < 10; i++) {
    cars.add(new Car(color(255, 0, 0), random(0, width), random(0, height), 2, 1));
  }
}

void draw() { 
  while(myPort.available() > 0){
     valA = myPort.read();
     valB = myPort.read();
     valC = myPort.read();
     valD = myPort.read();
  }
  background(100);
  //rect(x1, y1, a1, b1);
  fill(255);
  ellipse(x, y, 50, 50);
  
  if (valA > 100) {
    x = x - 3;
    x1 = x - 20;
    y1 = y;
   // a1 = 80;
   //b1 = 50;
  }
  if (valB > 100) {
    y = y - 3;
    x1 = x;
    y1 = y - 20;
    //a1 = 50;
    //b1 = 80;
  } 
  if (valC > 100) {
    x = x + 3;
    x1 = x + 20;
    y1 = y;
    //a1 = 80;
    //b1 = 50;
  } 
  if (valD > 100) {
    y = y + 3;
    x1 = x;
    y1 = y + 20;
    //a1 = 50;
    //b1 = 80;
  }
    
  if (y < 25){
    y = y + 3;
  }
  if (y > height - 25){
    y = y - 3;
  }
  if (x < 25){
    x = x + 3;
  }
  if (x > width - 25){
    x = x - 3;
  }
    

  for (int i = 0; i < cars.size(); i++) {
    Car car = cars.get(i);
    car.drive();
    car.display();
    if (dist(car.xpos, car.ypos, x, y) < 35) {
      cars.remove(i);
    }
  }
}


class Car { 
  color c;
  float xpos;
  float ypos;
  float xspeed;
  float yspeed;


  // The Constructor is defined with arguments.
  Car(color tempC, float tempXpos, float tempYpos, float tempXspeed, float tempYspeed) { 
    c = tempC;
    xpos = tempXpos;
    ypos = tempYpos;
    xspeed = tempXspeed;
    yspeed = tempYspeed;
  }

  void display() {
    stroke(0);
    fill(c);
    ellipse(xpos, ypos, 20, 20);
  }

  void drive() {
    xpos = xpos + xspeed;
    if (xpos > width) {
      xspeed = -xspeed;
    } else if (xpos < 0) {
      xspeed = -xspeed;
    }
    ypos = ypos + yspeed;
    if (ypos > height) {
      yspeed = -yspeed;
    } else if (ypos < 0) {
      yspeed = -yspeed;
    }
  }
}


//This is the Arduino code
int valA, valB, valC, valD, valE;

#include <Wire.h>
#include <ADXL345.h>


ADXL345 adxl;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  adxl.powerOn();

  //set activity/ inactivity thresholds (0-255)
  adxl.setActivityThreshold(75); //62.5mg per increment
  adxl.setInactivityThreshold(75); //62.5mg per increment
  adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
 
  //look of activity movement on this axes - 1 == on; 0 == off 
  adxl.setActivityX(1);
  adxl.setActivityY(1);
  adxl.setActivityZ(1);
 
  //look of inactivity movement on this axes - 1 == on; 0 == off
  adxl.setInactivityX(1);
  adxl.setInactivityY(1);
  adxl.setInactivityZ(1);
 
  //look of tap movement on this axes - 1 == on; 0 == off
  adxl.setTapDetectionOnX(0);
  adxl.setTapDetectionOnY(0);
  adxl.setTapDetectionOnZ(1);
 
  //set values for what is a tap, and what is a double tap (0-255)
  adxl.setTapThreshold(50); //62.5mg per increment
  adxl.setTapDuration(15); //625us per increment
  adxl.setDoubleTapLatency(80); //1.25ms per increment
  adxl.setDoubleTapWindow(200); //1.25ms per increment
 
  //set values for what is considered freefall (0-255)
  adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment
  adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment
 
  //setting all interrupts to take place on int pin 1
  //I had issues with int pin 2, was unable to reset it
  adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT,   ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT,    ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT,     ADXL345_INT1_PIN );
  adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT,   ADXL345_INT1_PIN );
 
  //register interrupt actions - 1 == on; 0 == off  
  adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
  adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
  adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT,  1);
  adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT,   1);
  adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);
}

void loop() {
  // put your main code here, to run repeatedly:
  //Serial.println(analogRead(0));
int x,y,z;  
  adxl.readXYZ(&x, &y, &z); //read the accelerometer values and store them in variables  x,y,z
  double xyz[3];
  double ax,ay,az;
  adxl.getAcceleration(xyz);
  ax = xyz[0];
  ay = xyz[1];
  az = xyz[2];
  
  
  if (ax < -1.2 || ax > 1.2 || ay < -1.2 || ay > 1.2 || az < -1.2 || az > 1.2){
    valE = 1;
  }
  else{
    valE = 0;
  }
  
  
  valA = map(analogRead(0), 0, 1023, 0, 255);
  valB = map(analogRead(1), 0, 1023, 0, 255);
  valC = map(analogRead(2), 0, 1023, 0, 255);
  valD = map(analogRead(3), 0, 1023, 0, 255);
  Serial.write(valA);
  //delay(10);
  Serial.write(valB);
  //delay(10);
  Serial.write(valC);
  //delay(10);
  Serial.write(valD);
  Serial.write(valE);
  delay(30);
  
  
}

Antonius Exercise 9: Media Controller

Exercise 8: Media Controller

Date: May 5th

Instructor: Antonius

Partner: Junan Zhang

Aim:  control the images and audio on a Processing sketch with a controller made with Arduino.

Material: Processing, Arduino, Arduino kit.

Process:

  1. We found a funny pet video on YouTube. The link is: https://www.youtube.com/watch?v=xDyQW3kL0Qg
  2. First, we decide to manipulate the speed of the speed of the video. The input that used to manipulate the speed were decided to be different voltage input. To change the voltage, we chose to use the potentiometer. The effect is shown in the video below.

IMG_1387

IMG_1384

3. Then we decided to make something more. We agreed on adding different color filter to the video, and use the temperature sensor as the input. When the temperature is high, the video will turn red, when the temperature is in the middle, the video will turn green, and when the temperature is low, the video will turn blue. The effect is shown in the video below.

IMG_1381

IMG_1385

 

//Procesing Code
import processing.serial.*;
Serial myPort;
import processing.video.*;
Movie mov;
//int newSpeed;
float newSpeed;
float newRed;
float newGreen;
float newBlue;

void setup() {
  myPort = new Serial(this, Serial.list()[2], 9600);
  size(400, 400);
  background(0);
  mov = new Movie(this, "FUNNY PET VIDEOS.mp4");
  mov.loop();
}
void movieEvent(Movie movie) {
  mov.read();  
}
void draw() {    
  image(mov, 0, 0, 400, 400);   
  tint(newRed, newGreen, newBlue, 150);
  while(myPort.available() > 0){
    //newSpeed = map(myPort.read(), 0, 100, 0.1, 2);
    //newRed = map(myPort.read(), 0, 100, 0.1, 2);
    if (myPort.read() > 60){
      newRed = 255;
      newGreen = 0;
      newBlue = 0;
    }
    else if (myPort.read() == 60){
      newRed = 0;
      newGreen = 255;
      newBlue = 0;
    }
    else if (myPort.read() < 60){
      newRed = 0;
      newGreen = 0;
      newBlue = 255;
    }
   
  }
  mov.speed(newSpeed);
  //float newSpeed = map(mouseX, 0, width, 0.1, 2);
  println(newSpeed);
  
} 


//Ardunio Code
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);  
}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorReading = analogRead(A0);
  //int sensorReading2 = analogRead(A1);
  //int val = map(sensorReading, 0, 1023, 0, 100);
  //Serial.println(sensorReading);
  //Serial.write(val);
  Serial.write(sensorReading);
}

Antonius: Exercise 8: Drawing Machine

Exercise 8: Drawing Machine

Date: Apr 28th

Instructor: Antonius

Partner: Yihui Liu

Aim: Create drawing machines by using an H-bridge to control stepper motors attached to mechanical arms.

Material: Arduino kit, 1 stepper motor, 1 SH75440NE IC chip, 1 5-volt power supply, 1 power plug, 1 potentiometer from your kit, 1 Arduino and USB cable from your kit, Laser-cut mechanisms, Pens that fit the laser-cut mechanisms.

IMG_1172

Process:

First I connected the Arduino and wires according the image provided. The picture is shown below.

IMG_1184

I refer to the sample code for the stepper motor, and we built up the half of the drawing machine together using the laser-cut mechanisms. We also tested it out. The picture and the video is shown below.

IMG_1175 2

IMG_1174

Then we cooperated with another group to form a whole drawing machine by connecting two arms together.

IMG_1180

We then add a current regulator and adjust the Arduino code accordingly to make the drawing machine changeable when changing the resistance.

IMG_1182

//Stepper motor control
#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}



//Stepper motor speed control
#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0;  // number of steps the motor has taken

void setup() {
  // nothing to do inside the setup
}
  
void loop() {
  // read the sensor value:
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  // set the motor speed:
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
  }
}

Antonius: Exercise 7 3D modeling

Exercise 7: 3D Modeling

Date: Apr 21th

Instructor: Antonius

Aim: Using Tinkercad, design a 3D model of a wearable device, a game controller or a security camera that utilizes one of the providing components or equipment.

Grove - 3-Axis Digital Accelerometer

Process:

The component I chose to hold in my design is a accelerometer, because I’m using it in my final project, and I might use a small devise to hold the accelerometer and connect it to my project.

I’m dividing my design into two separate parts, the container and the cap. Based on the length and the width of the accelerometer, I decided the inner diameter of the container to be 20mm*20mm. To fit the accelerometer better into the container I add two holes of semicircle at to edges.

屏幕快照 2017-05-04 下午5.51.32

 

The cap is bigger than the container in order to cover the whole container. Since there’s a plugging port at one side of the accelerometer, I made a rectangle hole on the top so that the wire can go through. To make the connection stronger between the cap and the container, I add two cylinders to the two edges of the container, and then made two holes accordingly for the cylinders to go through to form a stronger connection.

屏幕快照 2017-05-04 下午5.52.10

屏幕快照 2017-05-04 下午5.49.15

These are the pictures of my final design.

屏幕快照 2017-05-04 下午5.48.11

 

Discussion:

One problem I had was that when I was grouping up all the components in the container, a problem occurred that the rectangle hollow I made in the center will cut out the bottom half of the two cylinders placed on the edges. I was worried that I might need to do it all over again to create differently, instead of creating a hollow in the cube, another approach is to create four walls and a bottom to make the container. Then I consulted Marsela and she helped me solved my problem easily by changing the order of the combination. This impressed me a lot on how doing things in different order would have such a big effect.

Antonius: Tour to Shanghai Autodesk Headquarters

Exercise 6.2 Tour

Date: Apr 14th

Instructor: Antonius

Aim: Visit the Shanghai Autodesk Headquarters

The tour to the Shanghai Autodesk Headquarters was amazing. I got the chance to touch on the leading designing industry and know how they work. The two part that impressed me most was the designing process and the wide application of the technology in our life.

For the designing process, the most impressing product was the chair mentioned in the presentation. It clearly showed that how designing can change our life, and how advanced design we can achieve nowadays. The original chair was heavy because it’s solid, and in order to reduce the weight and increase the strength, engineers applied physics formulas to construct the hollow design of the chair. What impressing is that, by using computer to calculate and design, an even better chair was designed by the computer. The structure is not regular, but It can bear stronger force while reducing the weight. Using computer to design is becoming more and more popular because it’s faster in calculation and simulation.

After seeing the car and the tower model displaced in the exhibition, I was impressed by how these digital fabrication technology is being widely used in our life. Prototyping is a very important process in designing as well as industry constructions, using digital fabrication can reduce the time and material wastes in hand making prototypes. What’s more, since it’s controlled by computer, the prototype could be more accurate, which reduce the uncertainty during turning the design o the actual product.

Apart from the technology, I was also amazed by their idea that everyone should be able to Have access to tools that help them create their own design. With the wide spread of this self-designing idea, more and more people would be inspired and find their interest in designing. I believe in the near future, 3D printing would be as common as normal printers in our home, we can make our own product or use other’s high-tech designs shared in the internet to make our life better, but with much lower costs and a lot more fun.

These are some pictures taken during the tour.

IMG_0871IMG_0874IMG_0876IMG_0882IMG_0884IMG_0886IMG_0887IMG_0889

Antonius: Exercise 6 Stamp

Exercise 6.1 Stamp Making

Date: Apr 11th

Instructor: Antonius

Aim: Follow the DIY Rubber Stamp tutorial for the laser cutter and create your own custom AI file for your own stamp.

Materials: Adobe AI.

Exercises:

I mainly just followed the guild of the video:

  1. Create a new working space and adjust the unit of ruler.
  2. Import the original picture of the stamp.
  3. Draw a circle the same size as the stamp, keep and adjust the thickness of the border and remove the fill of the circle.
  4. Copy and paste the circle at the same place then adjust the size to meet the inner circle of the stamp.
  5. Repeat the last step to make the reference line for the text.
  6. Use the text tool to type the text on the stamp, then adjust the size and the font of the text.
  7. Draw the LED and the light dots using circles and squares from the shape tool.
  8. Draw a circle with only the fill color the size of the stamp.
  9. Put the circle and the stamp together and create the negative part of the stamp.
  10. Draw a circle without fill the size as the stamp and place it onto the stamp so that the laser cutter will cut.
  11. Reverse the stamp.

This is the final image of the stamp I made.

Stamp_Tutorial_image       Stamp

Discussion:

The whole process went on quite smooth. The part I got troubled was when I was creating the negative part of the stamp, I found that the LED I draw didn’t become what I expected, as it shown in the screen shot. I figured that the cause of this problem is that I didn’t group them together, so that the negative part turned out to be the negative of each line I drew in the LED. After grouping them together, the problem was solved, as shown below. Another minor mistake, but didn’t affect my project was that I forget to create new layers for each component in the stamp. Thanks to the fact that making the stamp is a small project. If it’s a large one that requires a lot of different components, putting them all in one layer will cause a big problem when I want to make adjustments. That’s the biggest lesson I learned in using AI for designing.

屏幕快照 2017-05-02 下午8.25.25

屏幕快照 2017-05-02 下午8.26.12

屏幕快照 2017-05-02 下午8.26.28

屏幕快照 2017-05-02 下午8.30.43

Antonius: Final Project Essay

Final Project

My final project will be an interactive game, where users can use his own physical movement to control the character inside the game.

My first thought of my final project was that it has to be a game, or something one can play with at least. Based on that idea, I started to think what kind of game I, or a user would like to play with. Personally, I myself is not a big game player. Although I’ve watched a lot of gaming videos, I only played a few. When thinking about the style of the game, I was inspired by a 2D shooting game called the Binding of Isaac. The character shoots bullets to defeat monsters coming from different directions, and after clearing all the monsters, the player can go to the next stage. Based on this idea, the basic style of my game would be controlling the character to kill monsters coming from different places.

Since I’m making a RPG game where there will be a character for the users to control, the second question for designing my game is what kind of character would I want to use? Because I was basing on an idea of a shooting game, the first thought was to create a character who uses guns to shoot monsters. But for a 2D shooting game, the only thing for the player to shoot is to press a button. Then why do you need an extra button on your hand when you can use the keyboard to shoot bullets? That’s why I decided to change my thought because I want my users to be more engaged in the game. Then a character just popped into my head – the character Reinhardt in Over Watch. He uses a shield and a hammer, which inspired me, because when I was controlling a character with short distance cold weapon, I would like to do the same movement with him. I remember when I was little, I was a big fan of the game Monster Hunter, and I would like to hold sticks in my hand and do the movements as the character pretending I was fighting a monster. That’s when I decided my character should use a shield and a sword, and the user can control the character to swing the sword by actual swing a handle or an actual sword by himself. This is how a game should be played, where the player can actual control the character by his actual movement. To actualize this design, I decided to make an actual handle with accelerometer imbedded to sense the movement of the player’s hand. Another handle for the shield with a button on it. And when the button is pressed, a shield will be generated in front of the character to protect him.

The next question would be how to control the character. In order to let the players to be fully into controlling the character, I decided that the players could control the character’s movement by the players’ own movement. To actualize this idea, I decided to make a mat with force sensor placed at four directions below it. There will be four arrows pointing four directions drawn on the mat, and when the users step on each arrow, the character will move along the same direction accordingly.

 

Antonius: Midterm Project (Remote controll maze)

Midterm Project: Remote-controlled maze

Date: Mar 30th

Partner: Saskia

Instructor: Antonius

Aim: To design our own project using Arduino and processing.

Materials: Arduino kit, Arduino, Processing, other materials: Cardboard, paint, hot glue, wooden panel, Marble, distance sensor.

Process:

  1. Designing:

After discussion, we decided to make a game related to maze solving. We decided to make an actual maze, and use a marble to run inside it. When it came to how to let the marble move around the maze, we had different ideas, including using servos to push the ball around, or blew air to push it. At last we decided to move the ball by changing the slope of the maze in different directions, so that the ball would be able to roll down the slope and move in different directions.

When thinking about how to change the slope of the maze, I first thought about using the kind of motor that can move up and down to push the sides of the maze up and down to create the slope. But after consulted with the professor, he told us that this kind of motor would cause a lot of trouble, and recommended us to use the servo instead. So I designed to put four servo at the four side of the maze to create the slope of the maze in four directions.

When thinking about how to control the maze, the first idea I had was to use the direction key on the keyboard to control the moving of the ball (the slope of the maze). But the professor’s question, “Why do we need the keyboard to control the maze” changed my mind. Why not use other physical input instead of digital input from the keyboard? So instead, we decided to use two tilt switch to sense the physical slope in four directions, and use it to control the maze that would tilt at the same direction.

unnamed unnamed-2

  1. Making the maze

We decided to make the maze using cardboard. So I designed the maze first, and then Saskia made and painted the maze. The picture of the design sketch and the finalized maze is shown below.

  1. Making the maze move

While Saskia was making the maze, I mainly focused on the Arduino codes and how to realize our theory to make the maze move. As we decided, the input would be the slope of the small hand-held platform served as the remote controller. The output would be the movement of the servo. The servo is connected onto the four edges of the platform below the maze. When the controller is leaning forward, the servo on the front would go down and the one on the back would go up to create a slope leaning forward. The other three directions were similar. The location of the servo, the connections and the codes are shown below.

IMG_0502 IMG_0503 IMG_0504 IMG_0505

IMG_1181

  1. Interacting Arduino with processing

Other than interactions between the controller and the maze, we decided to form the interaction between the physical world and the computer screen. The first interaction would be when the ball reach the ending position, an animation showing “You have arrived” will show on the screen. To realize this, a sharp IR distance sensor is placed at the end point, and when it senses something inside the range, the animation will appear on processing, triggered by Arduino. This animation was designed by Saskia, then I modified and incorporated it into the overall processing code. The second interaction I made is an indication of the direction of the ball on the screen. There are four arrows on the screen, and when the slope of the maze changes, the certain arrows on the screen will turn black according to the moving of the ball. For example, when the controller is leaning to the right, the servo on the left side will go up, the ball will then roll down the slope to the right, and the right arrow on the screen will turn black. That’s how the whole interaction work. The processing codes and the demonstration is shown below.

屏幕快照 2017-04-10 下午10.59.32屏幕快照 2017-04-11 上午12.11.23

 

  1. Modifying the maze

After we got everything done, all the servos, the controller, the animation were working, we discovered that there was a huge problem we need to solve. When we place the maze onto the flat platform with only the servos popping out, the maze would easily run away from the platform. After the presentation in the class, we decided to do something to make it stabilized. The solution we chose was to put the maze in a box, so that it won’t run away from the box. The wooden handle was too big for the box, so we sawed the handle thinner. Another problem was that the arm of the servo was too short to make a slope high enough. So we attached a longer arm to it. Due to the time limit, that’s what all we could do before the final show. And the maze was still not functioning very well.

IMG_1175

Reflection:

       I proposed another solution for the problem, which was to put the servos and the platform above the maze and use strings to control the slope of the maze. This way the maze won’t tilt around, and the change of the slope would be more stable. But we didn’t have enough time to do realize it. Another important thing I learned was about designing and time management. Our maze would functional well theoretically, but many other problems occurred and we found that we didn’t have enough time to solve all these amount of problems. We had a cool idea, controlling the maze by tilting our hand. But the process of realizing it was way harder than we expected.

//this is the Arduino code

int valA, valB, valC;

#include <Servo.h> 
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton1 = 2;
int pushButton2 = 4;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton1, INPUT);
  pinMode(pushButton2, INPUT);
  servo1.attach(9);
  servo2.attach(10);
  servo3.attach(11);
  servo4.attach(6);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState1 = digitalRead(pushButton1); //the tilt sensor
  int buttonState2 = digitalRead(pushButton2);
  // print out the state of the button:
  //Serial.println(buttonState1);
  //delay(100); // delay in between reads for stability
  //Serial.println(buttonState2);
  //delay(100); 

  //change the servo according to the state of the tilt switchs  
  if(buttonState1 < 0.5){
    servo1.write(0);
    delay(100);
    servo3.write(90);
    delay(100);
  }
  else if(buttonState1 > 0.5){
    servo1.write(90);
    delay(100);
    servo3.write(0);
    delay(100);
  }
  if(buttonState2 < 0.5){
    servo2.write(0);
    delay(100);
    servo4.write(180);
    delay(100);
  }
  else if(buttonState2 > 0.5){
    servo2.write(90);
    delay(100);
    servo4.write(90);
    delay(100);
  }
  valA = buttonState1;
  valB = buttonState2;
  valC = map(analogRead(0), 0, 1023, 0, 255);
  Serial.write(valA);
  Serial.write(valB);
  Serial.write(valC);
  //Serial.println(valC);
  delay(10);
}



//This is the processing code including the animation
import processing.serial.*;
Serial myPort;
int valA, valB, valC;
int a, b, c, d, e;
PFont f;  //declare an oject of type
String message = "you have arrived!";
//float theta;

void setup() { 
  myPort = new Serial(this, Serial.list()[2], 9600);
  size(400, 400);
  a = b = c = d = 200;
  f = createFont("Andale Mono",35,true);  //load the font
}

void draw() {
  //background(200);
  while(myPort.available() > 0){
     valA = myPort.read();
     valB = myPort.read();
     valC = myPort.read();
  }

//the arrow of the four directions
  triangle(300,120,300,280,350,200); 
  fill(a); //down
  triangle(120,300,280,300,200,350);
  fill(b); //left
  triangle(50,200,100,120,100,280);
  fill(c); //up
  triangle(120,100,280,100,200,50);
  fill(d); //right
  //println (valA);
  
  if(valA < 0.5){
    a = 100;
    c = 200;
  }
  else if(valA > 0.5){
    c = 100;
    a = 200;
  }
  if(valB > 0.5){
    b = 100;
    d = 200;
    e = 0;
  }
  else if(valB < 0.5){
    d = 100;
    b = 200;
  }
  if(valC > -1 && valC <60){ //if the ball is near the sensor, the animation will show
    pushMatrix();  
    background(0);
    e = 255;
    fill (e);
    textFont(f);  //call the text() function to display a message
    translate(width/2, height/2);
    rotate(radians(frameCount));
    textAlign(CENTER);
    text(message, 0, 0);
    //theta += 0.05;
    popMatrix();
    a = b = c = d = 255;
  }
  /*else if (valC > 20){
    background(200);
  }
  println(valC);
  */
}

Antonius: week 6 lab

Lab 6:

Date: Mar 17th

Instructor: Antonius

Partner: Roberto Noel

Aim: exchange data between Processing and Arduino using serial communication. Make a Processing sketch that tells Arduino to do something, and make the Arduino tell Processing to do something as well.

Materials: Arduino kit, Arduino, Processing.

Exercises:

  1. Processing to Arduino

We decided to use processing to control the on and off of different LEDs through Arduino. We created three virtual buttons on the screen using processing, giving them colors of red green and yellow. Using the mouse to press on the button will turn on the LED according to the color of the button. The design and the effects are shown below.

IMG_0400

IMG_0401

IMG_0402

  1. Arduino to processing

We decided to remain the design of the three lights in the processing. Instead of clicking on them, they became the output. The input we decided was to use the light sensor. Different color of the circles would turn black when different intensity of light was shined on the sensor. The connection and the effects are shown below.

IMG_0403

IMG_0406

Discussion:

In this project, we used the same settings to accomplish the two objectives. This might seem confusing when there are both input and output in processing and Arduino, but it helped me to gain better understanding when connecting the two together. I was confused by the port and how to use different codes to do the same thing in processing and Arduino. But after studied and wrote out the codes, it became clear to me when to use which in the project.

//This is the Arduino code

int valA, val;

void setup() {
  Serial.begin(9600);
  pinMode(11, OUTPUT); //red
  pinMode(10, OUTPUT); //yellow
  pinMode(9, OUTPUT); //green
}

void loop() {
  // receive a value from processing
  while (Serial.available()) {
    val = Serial.read();
  }
  // test the value
  if (val == 'R') {
    digitalWrite(11, HIGH);
  } else if (val == 'r') {
    digitalWrite(11, LOW);
  }
//  delay(10); // wait for Processing
  if (val == 'Y') {
    digitalWrite(10, HIGH);
  } else if (val == 'y') {
    digitalWrite(10, LOW);
  }
//  delay(10); 
  if (val == 'G') {
    digitalWrite(9, HIGH);
  } else if (val == 'g') {
    digitalWrite(9, LOW);
  }
//  delay(10); 

//send the value to processing
  valA = analogRead(0)/4;         // read voltage value 
//  Serial.println(valA);
  Serial.write(valA);
  delay(10); 
}



//This is the Processing code

import processing.serial.*;
Serial myPort;
int valA; //value from arduino
int x, y, z;
void setup() { 
  myPort = new Serial(this, Serial.list()[2], 9600);
  // Change the Serial.list()[0] to your port
  size(500, 200);
  
}
void draw() {
  ellipse(250, 100, 100, 100); //red 
  fill(x, 0, 0);
  ellipse(100, 100, 100, 100); //green
  fill(0, y, 0);
  ellipse(400, 100, 100, 100); //yellow
  fill(z, z, 0);
  
  // to send a value to the Arduino
  if (dist(mouseX, mouseY, 250, 100) < 50){
    if (mousePressed) {
      myPort.write('Y');
      //println('Y');
    } 
    else {
    myPort.write('y');
    //println('y');
    }
  }
  if (dist(mouseX, mouseY, 100, 100) < 50){
    if (mousePressed) {
      myPort.write('R');
      //println('R');
    } 
    else {
    myPort.write('r');
    //println('r');
    }
  }
  if (dist(mouseX, mouseY, 400, 100) < 50){
    if (mousePressed) {
      myPort.write('G');
      //println('G');
    } 
    else {
    myPort.write('g');
    //println('g');
    }
  }
  
//Get value from Arduino and change the color accordingly
  x = 255;
  y = 255;
  z = 255;
  while(myPort.available() > 0){
    valA = myPort.read();
  }
  println(valA);
  if(valA > 220 && valA < 250){
    x = 0;
  }
  else if(valA < 220 && valA > 200){
    z = 0;
  }
  else if(valA < 200){
    y = 0;
  }
}

Antonius: Stupid Pet Trick

Stupid Pet Trick

Date: Mar 10th

Instructor: Antonius

Aim: To make a small project that do something.

Materials: Arduino kit, Arduino, paper box.

Processes:

  1. Getting ideas: The inspiration I got was from my everyday life experience. Many times, especially on weekends, I tend to wake up late, but my good dreams always got disturbed by the bright sunlight outside. Other than that, sometimes when I was reading in the room, I list track of time and forgot to turn on the light even the light was bad for my eyes. Based on these experiences, I wonder if I could create something that can provide proper light for me.
  2. Designing: Based on the idea I formed, I decided that the input variable should be the brightness of the light, thus the sensor I chose was the light sensor. The output of my produce should be a proper light. At first I decided to use LEDs to provide different brightness of light, but the effect wasn’t good enough. So I turned to another idea, that is to make something that can close and open the curtain for you according to the light outside. Based on that idea, the output would then be the movement of a servo.
  3. Making the product:
  • First I would like to test the function of the light sensor. I wanted to create three kinds of conditions: low brightness, proper brightness, and high brightness. I used three LEDs with different colors to represent the three conditions: red for low, green for medium, and yellow for high. This is my first prototype:IMG_0808
  • Then I add the servo to the prototype. When the yellow LED was on, the servo would turn 180 degree, simulating the action of closing the curtain. This is how the modified prototype looks like and how it works:IMG_0810IMG_0812
  • Having the basic structure done, I decided to make it more applicable. So I made a model from a box that represented a house, and a piece of paper controlled by the servo to represent the curtain. I made four holes on it to show the LEDs and the light sensor, so that the effect can be easily seen and different light can be easily shine on the sensor. This is how it looks like in the box and how it works: IMG_0813
  • Since everything worked pretty well, I decided to make it look better, so I glued white paper on it to make it look neat. This how it looks afterwards:IMG_0347

 

Result and Presentation:

I named this project: Let GOOD Light Come to Be. I got the inspiration from the bible, where the god said, “Let light come to be.” This name indicated that the purpose of my project was to provide proper light. This is how it looked like and how it worked during the actual presentation:

IMG_0348

IMG_0814

Discussion:

The biggest obstacle I met during the project was actually the part I was looking for ideas. Because I learned a lot of kinds of input and out put, I was having a hard time combining them together to make a good project. So instead of starting from what I can do, I started to think of what I want, and that’s when I got my final idea based on my daily experiences. This is an important l learned from this project.

int RED = 13; 
int GREEN = 12;
int YELLOW = 7;
#include <Servo.h> 
Servo servo;

int val = 0;                      

void setup(){
     pinMode(RED,OUTPUT);
     pinMode(GREEN,OUTPUT);   
     pinMode(YELLOW,OUTPUT);            
     Serial.begin(9600);  
     servo.attach(9);      
}

void loop(){
     val = analogRead(0);         // read voltage value 
     Serial.println(val);        
     if(val>1000){                // if the value is larger than 1000, turn on hte red LED
          digitalWrite(RED,HIGH);
          digitalWrite(GREEN,LOW);
          digitalWrite(YELLOW,LOW);
          servo.write(180);
          //delay(500);
     }
     else if(val<1000 && val>950){  // if the value is between 1000 and 950, turn on hte green LED
          digitalWrite(RED,LOW);
          digitalWrite(GREEN,HIGH);
          digitalWrite(YELLOW,LOW);
          servo.write(180);
          //delay(500);
     }
     else if(val<950){          // if the value is lower than 950, turn on the yellow LED, then used the servo to close the curtain
          digitalWrite(RED,LOW);
          digitalWrite(GREEN,LOW);
          digitalWrite(YELLOW,HIGH);
          servo.write(0);
          //delay(500);
     }
     delay(10);                   
}