Our tangible interface makes it possible to display, swipe through, turn and zoom into images tangibly. We used Arduino, some physical parts and a bit of VB.NET code. (VB code is attached as a zip file)
Arduino code:
int zoomSensor = A0; // select the input pin for the potentiometer
int rotSensor = A1;
int swipeSensor1 = A2;
int swipeSensor2 = A3;
int zoomValue = 0;
int rotValue = 0;
int swSens1Val = 0, swSens2Val = 0;
int threshold = 80, swipeThresh = 400;
int bufZoom = 0, bufRot = 0;
int JITTER = 5, SMOOTH = 30;
const int smoothLength = 20;
int ZOOMSMOOTHER[smoothLength] = {0};
int ROTSMOOTHER[smoothLength] = {0};
// swipe variables
int swLcount = 0, swRcount = 0, swCountMax = 500;
int blockCounter = 0, blockMax = 100;
int lightOffset = 0;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
swSens1Val = analogRead(swipeSensor1);
swSens2Val = analogRead(swipeSensor2);
lightOffset = swSens2Val - swSens1Val;
}
void loop() {
// read the value from the sensors:
zoomValue = analogRead(zoomSensor);
rotValue = analogRead(rotSensor);
swSens1Val = analogRead(swipeSensor1);
swSens2Val = analogRead(swipeSensor2) - lightOffset;
// catch swipe to right
if(swSens1Val < swipeThresh){
if (swLcount == 0) swLcount = swCountMax;
else if(swLcount > 0) swLcount--;
}
else{
if (swLcount < swCountMax) swLcount++;
}
if(swSens2Val < swipeThresh){
if (swRcount == 0) swRcount = swCountMax;
else if(swRcount > 0) swRcount--;
}
else{
if (swLcount < swCountMax) swLcount++;
}
if(swSens1Val < swipeThresh && swSens2Val < swipeThresh){
if(blockCounter == 0){
if(swLcount <= swRcount){
Serial.print("R,0;");
swLcount = 0;
swRcount = 0;
}
else{
Serial.print("L,0;");
swLcount = 0;
swRcount = 0;
}
blockCounter = blockMax;
}
}
if(blockCounter > 0) blockCounter--;
// print values (improve jittering)
if((zoomValue != bufZoom) ||
(rotValue < (bufRot-JITTER) || rotValue > (bufRot+JITTER))){
zoomValue = smoothZoom(zoomValue);
rotValue = smoothRotation(rotValue);
bufZoom = zoomValue;
bufRot = rotValue;
Serial.print(zoomValue, DEC);
Serial.print(",");
Serial.print(rotValue, DEC);
Serial.print(";");
}
}
// these two functions smooth zooming and rotation with simple mean
int smoothZoom(int val){
unsigned int sum = 0;
memmove(ZOOMSMOOTHER+1, ZOOMSMOOTHER, (smoothLength-1)*2);
*ZOOMSMOOTHER = val;
for(int i=0; i<smoothLength; i++){
sum += ZOOMSMOOTHER[i];
}
return (sum / smoothLength);
}
int smoothRotation(int val){
unsigned int sum = 0;
memmove(ROTSMOOTHER+1, ROTSMOOTHER, (smoothLength-1)*2);
*ROTSMOOTHER = val;
for(int i=0; i<smoothLength; i++){
sum += ROTSMOOTHER[i];
}
return (sum / smoothLength);
}