Lab4 - Hammer Arcade Game
Description
I made a hammer game which scores how strong a user hits the ball with a hammer. I put FSR below the ball, reducing environmental noise by sending its value to processing program when it's above 360. Processing visualizes the measurement of power with bar and marking. For its appearance, I made reset button with Photocell that if the value of Photocell goes below certain light, the game will restart. Plus, each led represents the step of strength. For example, turning on only Red led means not enough power and turning on all leds means enough strength.
Components Used
- Arduino UNO
- 3* 220 Ohm Resistor, RGB LEDs
- Photocell
- FSR
- Tennis Ball and plastic bottle
Code
/*********** Arduino
/*
Hammer Game
Eungchan Kim
2013-02-26
*/
int fsrPin = A2;
int phoPin = A0;
int ledPin[3] = {11,9,10};
void setup()
{
Serial.begin(9600);
for (int i=0;i<3;i++){
pinMode(ledPin[i], OUTPUT); // declare the ledPin as an OUTPUT
}
}
void loop()
{
int val = analogRead(fsrPin);
int reset = analogRead(phoPin);
if (reset < 400){
digitalWrite(ledPin[0],LOW);
digitalWrite(ledPin[1],LOW);
digitalWrite(ledPin[2],LOW);
}
if (val <400){
digitalWrite(ledPin[0],HIGH);
}
else if (val >=400 && val < 800){
digitalWrite(ledPin[0],HIGH);
digitalWrite(ledPin[1],HIGH);
}
else {
digitalWrite(ledPin[0],HIGH);
digitalWrite(ledPin[1],HIGH);
digitalWrite(ledPin[2],HIGH);
}
// for input on Processing
if (val > 360){ // considering Noise
Serial.println(0);
Serial.println(val);
}
if (reset <400){
Serial.println(0);
}
delay(100);
}
/*********** Processing
/*
Hammer Game
Eungchan Kim
2013-02-26
*/
import processing.serial.*;
Serial port;
float a; // container height
int val = 10; //velocity of bar
float goal; // hit power
int flag = 0; // for reset
int cnt = 5; //bounding
void setup() {
size(255, 510);
port = new Serial(this,"COM3",9600);
port.bufferUntil('\n');
frameRate(30);
stroke(255);
a=height;
goal=height;
}
void draw() {
background(102);
// Box container
fill(255);
stroke(255);
rect(100, 50, 55, 460);
// Label
textSize(20);
fill(255);
text("Hammer Game", 50, 25);
textSize(10);
stroke(255,153,51);
for (int i=0;i<height-50;i=i+50){
text(i,70,510-i);
}
// Line
strokeWeight(5);
stroke(255,153,51);
line(155, a, 100, a);
if (a > goal && flag ==0){
a = height;
flag =1;
}
else if (a > goal && flag ==1){
a -= val;
}
else {
a = goal;
textSize(20);
fill(255,153,51);
text(int(height-goal),175,goal+7);
flag =0;
}
}
void serialEvent(Serial port){
goal = height-float(port.readStringUntil('\n'))*0.44;
println(goal);
}
Image
- Login to post comments
Drupal theme by Kiwi Themes.