Pot of Gold

For the programming part of the lab, I created a visualization which starts with a circle at the corner of the screen and a rectangle in the middle. As force is exerted on the FSR, the circle on the left corner starts travelling diagonally across the screen and the edges of the rectangle start rounding. At a point, the circle hides behind the rectangle as if it were a coin that went into a pot/jar.

This inspired mechanical part of my lab today. I used a pot to make contact with the FSR. Then I used a small ziploc bag full of coins to exert pressure on the FSR. The pressure could be measured by the number of quarters.

Arduino Sketch:

/* FSR testing sketch.

Connect one end of FSR to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Connect LED from pin 11 through a resistor to ground

For more information see www.ladyada.net/learn/sensors/fsr.html */

int fsrAnalogPin = 0; // FSR is connected to analog 0
int LEDpin = 13; // connect Red LED to pin 11 (PWM pin)
int fsrReading; // the analog reading from the FSR resistor divider
int LEDbrightness;

void setup(void) {
Serial.begin(9600); // We’ll send debugging information via the Serial monitor
pinMode(LEDpin, OUTPUT);
}

void loop(void) {
fsrReading = analogRead(fsrAnalogPin);
//Serial.print(“Analog reading = “);
//Serial.println(fsrReading);

// we’ll need to change the range from the analog reading (0-1023) down to the range
// used by analogWrite (0-255) with map!
LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
// LED gets brighter the harder you press
analogWrite(LEDpin, LEDbrightness);

delay(100);
Serial.println(fsrReading);
}

Processing Sketch:

/* PROCESSING SKETCH
* Arduino Ball Paint
* (Arduino Ball, modified 2008)
* ———————-
*
* Draw a ball on the screen whose size is
* determined by serial input from Arduino.
*
* Created 21 September 2016
* Noura Howell
*/
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = “COM3″;
Serial port;
String buf=””;
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10

int serialVal = 0;

void setup() {
size(700,700);
frameRate(10);
smooth();
background(40,40,40);
//noStroke();
port = new Serial(this, portname, 9600);
}

void draw() {
// erase the screen
background(40, 40, 40);

// draw the ball
fill(255, 255, 255);
//ellipse(150,150,serialVal,serialVal);
ellipse(serialVal,serialVal,150,150);
rect(200, 300, 300, 300, serialVal,serialVal, serialVal, serialVal);
}

// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
serialVal = int(buf);
println(“val=”+serialVal);
buf = “”;
}
}20160927_23281420160927_212835

 

Leave a Reply