rotating person
Description
Use FSR to control rotation of image
I tried to rotate a picture of person by the FSR sensor. I calculated the rotation angle to rotate 360 degree when the val is 255, so the rotation angle was PI*2*val/255 in radian. I was hoping to show movement, but it got to just add layers of the image on top.
http://www.youtube.com/watch?v=GEgq_jCXUBg
Arduino Code
/*
* Resistive Sensor Input
* Takes the input from a resistive sensor, e.g., FSR or photocell
* Dims the LED accordingly, and sends the value (0-255) to the serial port
*/
int sensorPin = 2; // select the input pin for the sensor
int ledPin = 9; // select the output pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(sensorPin); // read the value from the sensor, 0-1023
analogWrite(ledPin, val/4); // analogWrite (dimming the LED) can be between 0-255
Serial.println(val/4); // writing the value to the PC via serial connection
delay(50); // rest a little...
}
Processing Code
/*
* TUI Homework - Kylie Han
* Created 22 Febrary 2011
*/
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "COM4";
Serial port;
int val;
PImage img;
void setup() {
size(800,800);
frameRate(10);
smooth();
background(255,255,255);
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
if(0<port.available()) {
val = port.read();
}
println(val);
img = loadImage("chris.png");
translate(width/2,height/2);
rotate(PI*2*val/255);
image(img,-400,-400,800,800);
}