Description:
I used my trusty water bottle as the device to control a simple visualizer in Processing. When pressure is applied from the water bottle to the FSR, a circle is generated. It grows and moves diagonally as more pressure is applied until the whole screen is covered.
Components Used
1- Arduino Uno
2- 1K Ω Resistor
1- Breadboard
1- Force sensitive resistor
1- Photocell
1- Water Bottle
Processing Code
/*
* Arduino Ball Paint
* Modified by Anthony Suen 2013
* ----------------------
*
* 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
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
int fsr=0;
void setup() {
size(300,300);
frameRate(10);
smooth();
background(40,40,40);
noStroke();
println(Serial.list());
port = new Serial(this, Serial.list()[8], 9600);
}
void draw() {
background(fsr, 255-fsr, 255);
drawball(fsr,fsr,fsr);
}
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) {
fill(155,100,240);
ellipse(x,y,fsr,r);
//quad(60-fsr, 50-fsr, 40-fsr, 40-fsr, 40-fsr, 40-fsr, 30-fsr, 50-fsr);
//noStroke();
//translate(fsr, 48, fsr);
//sphere(28);
}
// 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);
val = val / 4;
fsr = val;
println("val="+val);
buf = "";
}
}
Arduino Code
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(200); // delay in between reads for stability
}
- Login to post comments