DESCRIPTION
In this lab, I explored how Force Sensitive Resistors (FSR) can be used to create visualizations through the processing program and the LED_FSR code provided by the class. The FSR acts similarly to the pots in that they're able to register varying degrees of input through the amount of force placed on the sensor. By pairing it with a visualizer, we can really experiment and play with ways to create images and art through our interactions with the FSR. In this assignment, I chose to pair my FSR with the "X" button on my PSP and having every press displaying an "X" in the java applet. The size also refers to how hard I press down on the "X" button. During times of higher game stress I find myself pressing harder on the controls than during times of relaxed gameplay, so it's interesting to see that momentum visualized.
COMPONENTS USED
1 - Arduino Uno
1 - Breadboard
1 - Green LED
1 - USB Cable
1 - 10k Resistor
1 - 220 Ohm Resistor
1 - Force Sensitive Resitor
1 - PlayStation Portable
8 - Wires
ARDUINO CODE
/*
* Resistive Sensor Input
* Takes the input from a resistive sensor, e.g., FSR or photocell
* Dims the LED accordingly, and sends the value (0-255) to the serial port
*/
int sensorPin = 0; // select the input pin for the sensor
int ledPin = 11; // select the output pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(sensorPin); // read the value from the sensor, 0-1023
analogWrite(ledPin, val/4); // analogWrite (dimming the LED) can be between 0-255
Serial.println(val/4); // writing the value to the PC via serial connection
delay(50); // rest a little...
}
PROCESSING CODE
/*
* Arduino Ball Paint
* (Arduino Ball, modified 2008)
* ----------------------
*
* Draw balls randomly on the screen, size controlled by a device
* on a serial port. Press space bar to clear screen, or any
* other key to generate fixed-size random balls.
*
* 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 = "/dev/tty.usbmodem1411"; // or "COM5"
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
void setup() {
size(600,600);
frameRate(10);
smooth();
background(250,250,250);
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
}
void keyPressed() {
if(key == ' ') {
background(40,40,40); // erase screen
}
else {
int x = int(random(0,width));
int y = int(random(0,height));
drawball(x,y, 50);
}
}
// draw balls
void drawball(int x, int y, int r) {
for (int i=0; i<100; i++ ) {
fill(255-r,r,240);
stroke(r,200,255-r);
ellipse(i+120,i+120,r,r);
fill(240,255-r,r);
stroke(255-r,r,200);
ellipse(480-i,480-i,r,r);
fill(r, 240, 255-r);
stroke(200,255-r,r);
ellipse(480-i,i+120,r,r);
fill(240, r, 255-r);
stroke(255-r,200,r);
ellipse(i+120,480-i,r,r);
}
}
// 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);
int x = int(random(0,width));
int y = int(random(0,height));
drawball(x,y,val);
buf = "";
}
}
- Login to post comments