Description
For the visualization, I changed the code around so that the user input results in a visualization that resembles a tear-shaped layers of colors (in Processing). The x-position of the visualization is consistent (always in the middle). The y-position and the size of the circles change depending on the user's input--weaker input means smaller circle & higher y-position, stronger input means bigger circle & lower y-position. Although the colors are determined at random, I narrowed down the range to (127,255) which resulted in pastel colors.
For the mechanical construction, I attached the FSR to a plush doll and when there's user input, the LED lights up. The brightness of the LED depends on how hard the user presses the sensor. The sensor is surprisingly sensitive to the user's pressure although the plush doll is very soft. Prior to this, I tried using a velcro pad on top of the FSR; however, the tactile feedback wasn't satisfying enough compared to the plush doll.
Components
- 1x 10k Ohm Resistor
- 1x 220 Ohm Resistor
- 1x Red LED
- 1x FSR
- 1x Arduino Uno
- 1x Breadboard
- 1x Macbook Pro
Code
PART 1
/*
* 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
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
void setup() {
size(400,400);
frameRate(24);
smooth();
background(40,40,40);
noStroke();
/*
Run the code once with this print statement to see a list of available serial ports.
Make a note of the number next to the port you'd like to use
*/
//println(Serial.list());
/* Once you know the number of the port you want to use Replace the "0" in the code below
with the port number. For instance, if you wanted to use port number 4 in the list, then
the code should say: port = new Serial(this, Serial.list()[4], 9600);
*/
port = new Serial(this, Serial.list()[4], 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, int xPos, int yPos) {
for (int i=0; i<100; i++ ) {
int red = int(random(127,255));
int green = int(random(127,255));
int blue = int(random(127,255));
fill(red, green, blue);
ellipse(xPos,yPos,r,r);
// fill(255-i,i,240);
// ellipse(x,y,r,r);
}
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
/* this print statement will allow you to see whether or not Processing can "hear" anything that
Arduino is sending. It should print all the changing values of the FSR or Photocell in your circuit
If nothing is printing, you probably picked the wrong serial port.
*/
println(c);
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));
int xPos = int(random(0,width));
int yPos = int(random(0,height));
drawball(x,y,val,width/2,val+50);
buf = "";
//background(40,40,40); // erase screen
}
}
PART 2
// Analog pin settings
int aIn = 0;
// Digital pin settings
int aOut = 13;
// Values
int aVal = 0;
// Variables for comparing values between loops
int i = 0; // Loop counter
int wait = (1000); // Delay between most recent pot adjustment and output
int checkSum = 0; // Aggregate pot values
int prevCheckSum = 0;
int sens = 6; // Sensitivity threshold, to prevent small changes in
// pot values from triggering false reporting
// FLAGS
int PRINT = 1; // Set to 1 to output values
int DEBUG = 1; // Set to 1 to turn on debugging output
void setup()
{
pinMode(aOut, OUTPUT); // sets the digital pins as output
Serial.begin(9600); // Open serial communication for reporting
}
void loop()
{
i += 1; // Count loop
aVal = analogRead(aIn) / 4; // read input pins, convert to 0-255 scale
analogWrite(aOut, aVal); // Send new values to LEDs
if (i % wait == 0) // If enough time has passed...
{
checkSum = aVal; // ...add up the 3 values.
if ( abs(checkSum - prevCheckSum) > sens ) // If old and new values differ
// above sensitivity threshold
{
if (PRINT) // ...and if the PRINT flag is set...
{
Serial.print("A: "); // ...then print the values.
Serial.print(aVal);
PRINT = 0;
}
}
else
{
PRINT = 1; // Re-set the flag
}
prevCheckSum = checkSum; // Update the values
if (DEBUG) // If we want debugging output as well...
{
Serial.print(checkSum);
Serial.print("<=>");
Serial.print(prevCheckSum);
Serial.print("\tPrint: ");
Serial.println(PRINT);
}
}
}
- Login to post comments