ASSIGNMENT
Connect a Force Sensitive Resistor (FSR) and create and Arduino program to transmit the FSR input value from the Uno to Processing where it can be received and used as a value in a drawing program.
In addition, create a unique hardware piece to apply pressure to the FSR.
MATERIALS USED
1 FSR, 1 10k ohm resistors, 2 buttons, 2 foam ear plus, 1 rubber band
ARDUINO CODE
int FSR_pressure = 5; // select the input pin for the FSR
void setup()
{
Serial.begin(9600);
}
void loop()
{
// read the value from the FSR, between 0 - 1023, and map from 0-100
int val = map(analogRead(FSR_pressure), 0, 1023, 0, 500);
Serial.println(val); //Send serial data to computer
delay(50); //wait to refresh brightness
}
PROCESSING CODE
import processing.serial.*;
Serial port;
float radius = 0; // amplitude is based on the pressure on the FSR mapped from 0 - 100
float r = 0; // store previous radius
void setup()
{
size(500,500);
background(255,255,255);
fill(0,0,0);
port = new Serial(this, "/dev/tty.usbmodemfa131", 9600);
port.bufferUntil('\n');
}
void draw() {
if (radius != r){
int x = int(random(0,500));
int y = int(random(0,500));
ellipse(x,y,radius,radius);
r = radius;
}
else {
background(255,255,255);
}
}
void serialEvent (Serial port)
{
radius = float(port.readStringUntil('\n'));
}