Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Picture Zoomer

Project Members: 
Srinivasan Ramaswamy

Programming

Description

Image zoom is controlled with the help of a potentiometer, to make the zooming process more intutive and natural.

 

Components Used

Arduino board

1 resistor

1 potentiometer

Arduino Code

/*
* one pot fades one led
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int potPin = 0; // select the input pin for the potentiometer
int ledPin = 13; // select the 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(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val/4);
delay(100);
// analogWrite(ledPin, val/4); // analogWrite can be between 0-255
}

Processing Code

//Srinivasan Ramaswamy
//Picture Zoomer
import processing.serial.*;

String portname = "COM7";
Serial port;
PImage img;
int w,h,sw,sh;
int counter=0;
int prevVal=0;
// Change this to the portname your Arduino board

String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10

void setup()
{
size(1024,800);
frameRate(30);
// The background image must be the same size as the parameters
// into the size() method. In this program, the size of "cute.jpg"
// is 200 x 200 pixels.
img = loadImage("cute.jpg");
port = new Serial(this, portname, 9600);
}

void draw()
{
image(img,0,0,width,height);
// a = (a + 1)%(width+32);
// stroke(226, 204, 0);
// line(0, a, width, a-26);
// line(0, a-6, width, a-32);
}

void keyPressed() {
if(key=='+') {
width = width + 10;
height = height + 10;
}
if(key=='-') {
width = width - 10;
height = height - 10;
}

// drawImg();
}

void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
int val = int(buf);
if (counter==0){
int firstVal = val;
}
if (val>prevVal){
w = val%10;
h = val%10;
width = width+w;
height = height+h;
}
else if(val<prevVal){
w = val%10;
h = val%10;

width = width-w;
height = height-h;
}
print("val="+val);
println(" prevVal="+prevVal);
if (val!=prevVal){
prevVal = val;
}
// int x = int(random(0,width));
// int y = int(random(0,height));
// drawball(x,y,val);
buf = "";
// background(40,40,40); // erase screen
}
}

 

Zoom Out: Picture zoomed out with the use of potentiometerZoom Out: Picture zoomed out with the use of potentiometer

Zoom In: Picture zoomed in with the use of potentiometerZoom In: Picture zoomed in with the use of potentiometer

Mechanical

The FSR is attached to a ball pen to detect when the pen is switched on/off. THe LED will glow when the ball pen is ready to write and it wil get switched off when its lead is inside.

 

Ball Pen with FSRBall Pen with FSR


Powered by Drupal - Design by Artinet