Interactive Project – “Hand Closer to Dog” Mahal Schroeder

IMG-4717

 

IMG-4725

Arduino Code

#include <Mouse.h>
const int trigpin= 8;
const int echopin= 7;
long duration;
int distance;

const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{ // initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(trigpin,OUTPUT);
pinMode(echopin,INPUT);
Serial.begin(9600);

}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
Serial.println(“ON”);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
Serial.println(“OFF”);
}

digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
duration=pulseIn(echopin,HIGH);
distance = duration*0.034/2;
Serial.println(distance);

}

Processing Code

import processing.serial.*;
PGraphics pg;
PImage ONE;
PImage TWO;
PImage THREE;
PImage dog;
PImage dog2;
PImage heart;
PImage cloud;
PImage gog;
PImage talk;
Serial myPort;
String data=” “;
PFont myFont;
int x = 0;
int y = 200;
int r = 750;
int w = (int) random(-20, 20);
int score = 0;
int highScore;
int holder;
boolean play = true;

void mousePressed()
{ w = (int) random(-40, 40);
println(“NEW W”, w);
play = true;
game(data, play, w);
y = 0;
score = 0;
holder = 0;
}

void game(String data, boolean play, int wild)
{
if (play == true);
{
image(ONE, 0, 0);
int a = (int) random(0, 4);
if (a == 1)
image(ONE, 0, 0);
if (a == 2)
{image(TWO, 0, 0);}
else
{image(THREE, 0, 0);}
image(dog, x, y);
score = score + 10;
textSize(20);
text(“Miles Away: ” , 10, 20);
text(score, 125, 20);
if (data.equals(“0”))
{
y = y- 45 + w;
}
else if (data.equals(“1”))
{
y = y -40 + w;
}
else if (data.equals(“2”))
{
y = y -30 + w;
}
else if (data.equals(“3”))
{
y = y -20 + w;
}
else if (data.equals(“4”))
{
y = y -10 + w;
}
else if (data.equals(“5”))
{
y = y -5 + w;
}
else if (data.equals(“6”))
{
y = y + 5 + w;
}
else if (data.equals(“7”))
{
y = y + 10 + w;
}
else if (data.equals(“8”))
{
y = y + 20 + w;
}
else if (data.equals(“9”))
{
y = y + 30 + w;
}
else
{y = y + 20 + w;}
}
}
void setup()
{
size(700,450);
noStroke();
frameRate(7);
myPort = new Serial(this, “COM3”, 9600);
myPort.bufferUntil(‘\n’);
ONE = loadImage(“ONE.png”);
TWO = loadImage(“TWO.png”);
THREE = loadImage(“THREE.png”);
dog = loadImage(“pup.png”);
dog2 = loadImage(“pup2.png”);
heart = loadImage(“heart.png”);
cloud = loadImage(“1.png”);
gog = loadImage(“gog.png”);
talk = loadImage(“talk.png”);
}

void draw()
{
println(w);
play = true;
game(data, play, w);

if (y > 450)
{y = 1000;
play = false;
clear();
image(gog, 100, 40);
textSize(35);
text(“Without any warning,”, 10, 50);
text(“he suddenly fell”, 10, 110);
text(“back down”, 10, 170);
text(“to earth”, 10, 230);
textSize(20);
text(“Click to play again”, 10, 400);
}
if (y < -120)
{y = -1000;
play = false;
score = score + -10;
clear();
holder = score;

if (holder> highScore)
{highScore = holder;}
image(gog, 100, 40);
textSize(35);
text(“And just like that,”, 10, 60);
text(“he ascended into”, 10, 120);
text(“the great”, 10, 180);
text(“Unkown”, 10, 240);
textSize(20);
text(“Score:”, 10, 370);
text(score, 100, 370);
text(“High Score: “, 10, 395);
text(highScore, 150, 395);
text(“Click to play again”, 10, 415);
}

}

void serialEvent(Serial myPort)
{
data = myPort.readStringUntil(‘\n’);
data = trim(data);
}

One thought on “Interactive Project – “Hand Closer to Dog” Mahal Schroeder

Leave a comment