Interactive Art [Week 11] - Installation

Installation

First attempt for game:


The problem with this approach was that the rotation for the car stayed at the center of the canvas but the car changes it's relative position to the center so the further the car is, the movements become unrealistic.

The second approach to the game was to do a "lane changer" so the potentiometer controls the X position while the buttons controls the Y position. In this example the buttons functions as gas and brake pedals and the potentiometer as a steering wheel.





Arduino Code:
int breakPin = 7;
int gasPin = 2;

int potPin = 2;

void setup() {
Serial.begin (9600);
pinMode(breakPin, INPUT);
pinMode(gasPin, INPUT);
}

void loop() {
int breakVal = digitalRead(breakPin);
int gasVal = digitalRead(gasPin);
int potVal = analogRead(potPin);

Serial.print(breakVal);
Serial.print(",");
Serial.print(gasVal);
Serial.print(",");
Serial.print(potVal);
Serial.println();

delay(50);

}

Processing Code:
import processing.serial.*;
Serial myPort;
int breakVal = 0;
int gasVal = 0;
int potVal = 0;

int bajarLinea;

PImage ParkingLot;
PImage Car;

int carY;
int carX;
int carRot;

void setup()
{
 size(500,500);
 printArray(Serial.list());
 String portname = Serial.list()[5]; // <- change the number according to your port setup
 myPort = new Serial(this, portname, 9600);
 myPort.bufferUntil('\n');

 ParkingLot = loadImage("parking.jpeg");
 Car = loadImage("car.png");


 carY = 0;
 carX = 0;
 carRot = 0;

 bajarLinea = -200;
}

void draw(){
 background(150);

 if (bajarLinea <= 100){
   bajarLinea = bajarLinea + 5;
 }else{bajarLinea = -200;}

 pushMatrix();

 translate(width/2, height/2);
 rotate(carRot);
 translate(-Car.width/2, -Car.height/2);
 linea();
 image(Car, carX, carY);

 popMatrix();



       if (potVal <= 400){
         carX = carX + 3;
       }
   
       if (potVal >= 401 && potVal <= 499){
         //fill(0,0,255);
       }

       if (potVal >= 500 && potVal <= 1023){
         carX = carX - 3;
       }

 if (breakVal == 1){
   //if(carY >= -175 && carY <= 175){
     //fill(255,0,0);  
     carY = carY + 5;
   //}
 }else if(gasVal == 1){
     //if(carY >= -175 && carY <= 175){
       //fill(0,255,0);
       carY = carY - 5;
     //} 
   }else {
     //fill(255);
   }

 float eSize = potVal / 10;
 //ellipse(width/2, height/2, eSize, eSize);
}

void serialEvent(Serial myPort){
 String myString = myPort.readStringUntil('\n');
 if (myString != null) {
   // remove whitespaces
   String trimmed = trim(myString);

   // separate signals into multiple values with delimiter(comma)
   String[] vals = split(trimmed, ',');

   // makes sure we received all 2 values

   if (vals != null && vals.length == 3){
     println(vals[0] + " " + vals[1]+ " " + vals[2] + " " + carRot);
     // 1st value is button value
     breakVal = int(vals[0]);
     // 2nd valus is IR sensor value
     gasVal = int(vals[1]);
     //3rd valus is IR sensor value
     potVal = int(vals[2]);
   }
 }
}

void linea(){
    rect(100, bajarLinea-150, 5, 55);
    rect(-50, bajarLinea-150, 5, 55);
  rect(100, bajarLinea, 5, 55);
  rect(-50, bajarLinea, 5, 55);
    rect(100, bajarLinea+150, 5, 55);
    rect(-50, bajarLinea+150, 5, 55);
  rect(100, bajarLinea+300, 5, 55);
  rect(-50, bajarLinea+300, 5, 55);
    rect(100, bajarLinea+450, 5, 55);
    rect(-50, bajarLinea+450, 5, 55);
  rect(100, bajarLinea+600, 5, 55);
  rect(-50, bajarLinea+600, 5, 55);
}

Comentarios

Entradas más populares de este blog

Interactive Art [Week 5] - Arrays

Interactive Art [Week 8] - Interactive Button