Description
In this lab, we explored two new analog sensors-- photocells ("phots") and Force Sensitive Resistors ("FSRs"). We used these sensors to control a GUI using Processing.
For my homework, I used Processing and Arduino to control a horizontal line and the background color of my display, using an FSR. I placed an orange on my FSR to focus the amount of force applied to the sensor.
https://vimeo.com/76492698
Components Used
1- Arduino Uno
1- Breadboard
1- USB cable
5- Jumper wires
1- 10K Ohm Resistor
1- Force Sensitive Resistor (FSR)
1- Orange
Arduino Code
/* Kristina Hart Lab 4
Serial Call adapted from Jeremy Blum "Arduino: Serial Communication and Processing"
*/
int fsrPin = A0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int val = map(analogRead(fsrPin), 0, 1023, 0, 255);
Serial.println(val);
delay(50);
}
Processing Code
/* Kristina Hart Lab 4
Processing adapted from Jeremy Blum "Arduino: Serial Communication and Processing"
and Processing 2 "Setup and Draw" (http://processing.org/examples/setupdraw.html)
*/
import processing.serial.*; //import serial library
Serial port; //create serial object
float brightness = 0;
void setup()
{
size(640, 255); // Size must be the first statement
stroke(255); // Set line drawing color to white
frameRate(30);
port = new Serial(this, "/dev/tty.usbmodem1421", 9600);
port.bufferUntil('\n');
}
void draw()
{
background(brightness, 200-brightness, 255-brightness);
line(0, brightness, width, brightness);
}
void serialEvent (Serial port)
{
brightness = float(port.readStringUntil('\n'));
}
- Login to post comments