Description
Test your strength on this virtual high striker game by striking the mounted FSR.
Arduino Code
/*created 2006
* by David A. Mellis
* modified 14 Apr 2009
* by Tom Igoe and Scott Fitzgerald
*
* This example code is in the public domain.
*
* http://www.arduino.cc/en/Tutorial/Graph
*/
void setup() {
// initialize the serial communication:
Serial.begin(9600);
}
void loop() {
// send the value of analog input 0:
Serial.println(analogRead(A0));
// wait a bit for the analog-to-digital converter
// to stabilize after the last reading:
delay(10);
}
Processing Code
/*
* High Striker
* (Arduino Ball, modified 2011)
* by Andrea Hsieh
* ----------------------
*
*
*
* Receives an ASCII number over the serial port,
* terminated with a carriage return (ascii 13) then newline (10).
*
* This matches what Arduino's " Serial.println(val)" function
* puts out.
*
* Created 25 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "COM3"; // or "COM5"
Serial port;
String buf="";
int cr = 13;
int lf = 10;
void setup() {
size(150,700);
frameRate(10);
smooth();
background(0,0,0);
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
}
void keyPressed() {
if(key == ' ') {
background(0,0,0); // erase screen
}
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
int val = int(buf);
println("val="+val);
buf = "";
background(0,0,0); // erase screen
if (val < 10)
{
background(0,0,0);
} if (val > 50) {
textSize(10);
text("weak", 60 , 650);
} if (val > 300) {
textSize(20);
text("average", 40, 510);
} if (val > 500)
{ textSize(30);
text("average", 15, 360);
text("above", 25, 325);
} if (val > 700)
{textSize(47);
text("strong", 0, 170);
} if (val > 900)
{ textSize(60);
text("BOSS", 0, 40);
}
}
}