Lab 4: Stress Ball
Description:
I stuck the photocell sensor into a stress ball and modified the processing code to make the squeezing power of the hand visualized. In order to improve the accuracy, I set the default value of the received power not zero but a minus number (after several tries) that it can offset the squeezing power from the stress ball itself.
Components:
1 - Arduino Uno
1 - Photocell Sensor
1 - LED Light (Red)
1 - Breadboard
1 - 220 ohm resistor
1 - 10k ohm resistor
1 - Stress Ball
Codes:
/* Processing Codes
*/
import processing.serial.*;
String portname = "/dev/tty.usbmodem1421";
Serial port;
int time = 0;
void setup() {
size(800,400);
frameRate(100);
background(#000000);
smooth();
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
}
void serialEvent (Serial p) {
// read the string from serial port, one line each time
String serial_string = port.readStringUntil('\n');
if(serial_string != null) {
float anger_level = float(serial_string) - 80;
anger_level = map(anger_level*7, 0, 1023, 0, 350);
// draw red lines:
stroke(300,0,0);
line(time, height, time, height - anger_level);
// if ran out of the space, then return to the beginning and erase screen
// otherwise, increase the time (horizontal) value
if (time >= width) {
time = 0;
background(#000000);
}
else {
time ++;
}
}
}
- Login to post comments
Drupal theme by Kiwi Themes.