Description
For the programming application, I wrote a program that has 6 circles that fade into different colors depending on how much pressure you apply to the force sensor. The 6th circle doesn't appear unless you apply pressure to it. I hope to use this as part of my group's midterm project, since we plan on using a touch surface with multicolored LEDs.
For the mechanical application, I tried to see if I could make an alert system for my apartment's welcome mat. Obviously the setup for a practical application would have the LED be inside so people in the house could get a visual cue that someone was outside, but the purpose of this experiment was to see if the force sensor could sense through our fairly thick welcome mat, which it did.
Materials
1 - Arduino
1- Force Sensor
1 - 220-ohm resistor
1 - 110-ohm resistor
1 - red LED
Code
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbmodem1421"; // or "COM5"
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
void setup() {
size(640, 360);
noStroke();
colorMode(RGB);
fill(0.4);
port = new Serial(this, portname, 9600);
}
void draw() {
}
void showBall(int val) {
background(0);
fill(val, 255-val, val/4);
ellipse(100, 100, 100, 100);
fill(255-val, val, val/4);
ellipse(200, 200, 200, 200);
fill(val, val/4, 255-val);
ellipse(300, 100, 100, 100);
fill(val/4, val, 255-val);
ellipse(300, 300, 100, 100);
fill(val/4, 255-val, val);
ellipse(100, 300, 100, 100);
fill(255-val, val/4, val);
ellipse(200, 200, 100, 100);
}
// 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);
println("val="+val);
showBall(val);
buf = "";
}
}
- Login to post comments