Description
Allows the user to control an image of a globe with a pot and a FSR. When you turn the pot, the globe spins. When you squeeze the FSR, the globe turns to night.
Components Used
Arduino Diecimila
2 resistors
1 potentiometer
1 FSR
various wires
*note that the images below have other wires and sensors, however they were not utilized for this program.
Arduino Code
/*
* sends serial out from a pot and a FSR
*/
int FSRPin = 0; // select the input pin for the FSR
int potPin = 1; // select the input pin for the potentiometer
int FSRVal = 0; // variable to store the value coming from FSR
int potVal = 0; // variable to store the value coming from pot
void setup() {
Serial.begin(9600);
}
void loop() {
FSRVal = analogRead(FSRPin); // read the value from FSR, between 0 - 1024, for dimming
potVal = analogRead(potPin); // read the value from pot, between 0 - 1024, for blinking
Serial.print("F");
Serial.println(FSRVal); //pressure
Serial.print("P");
Serial.println(potVal); //pot
}
Processing Code
/*
*
* This program draws a globe, which rotates when a pot is turned and
* changes from day to night when the FSR is pressed.
*
* Shawna Hein
* TUI
* 9/27/07
*
*/
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/ttyUSB0"; // or "COM5"
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
int currentPic=0;
int numFrames = 31; // The number of frames in the animation
int frame = 0;
PImage[] images = new PImage[numFrames];
void setup()
{
size(300, 250);
frameRate(40);
//load all the images of the globe into an array
images[0] = loadImage("bscap004.jpg");
images[1] = loadImage("bscap005.jpg");
images[2] = loadImage("bscap006.jpg");
images[3] = loadImage("bscap007.jpg");
images[4] = loadImage("bscap008.jpg");
images[5] = loadImage("bscap009.jpg");
images[6] = loadImage("bscap010.jpg");
images[7] = loadImage("bscap011.jpg");
images[8] = loadImage("bscap012.jpg");
images[9] = loadImage("bscap013.jpg");
images[10] = loadImage("bscap014.jpg");
images[11] = loadImage("bscap015.jpg");
images[12] = loadImage("bscap016.jpg");
images[13] = loadImage("bscap017.jpg");
images[14] = loadImage("bscap018.jpg");
images[15] = loadImage("bscap019.jpg");
images[16] = loadImage("bscap020.jpg");
images[17] = loadImage("bscap021.jpg");
images[18] = loadImage("bscap022.jpg");
images[19] = loadImage("bscap023.jpg");
images[20] = loadImage("bscap024.jpg");
images[21] = loadImage("bscap025.jpg");
images[22] = loadImage("bscap026.jpg");
images[23] = loadImage("bscap027.jpg");
images[24] = loadImage("bscap028.jpg");
images[25] = loadImage("bscap029.jpg");
images[26] = loadImage("bscap030.jpg");
images[27] = loadImage("bscap031.jpg");
images[28] = loadImage("bscap032.jpg");
images[29] = loadImage("bscap033.jpg");
images[30] = loadImage("bscap034.jpg");
//load the first image;
image(images[0], 0, 0);
port = new Serial(this, portname, 9600);
}
void draw()
{
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
String val = buf;
float num = 0;
char code = val.charAt(0);
String s = val.substring(1);
int number = int(s);
float numm = 0;
int inumm = 0;
println("code="+code);
println("number="+number);
if(code=='F'){
//if the data is from the FSR
if(number>5){
// if someone's actually pressing the FSR
numm = number/4;
inumm = round(numm);
tint(102,153,(256-inumm));
}
else {};
}
else if(code=='P'){
//If the data is from the pot
//Rotate the globe by calling each image
if(number!=0){
num = number/34;
}
currentPic = round(num);
image(images[currentPic], 0, 0);
}
buf = "";
}
}
Item
pot and FSR View 1
pot and FSR View 2
Screenshot Globe
Screenshot Globe2
Comments
Shawna, I distinctly
Shawna, I distinctly remember leaving you a comment! I have no idea what happened! Anyways, I just wanted to say great job mapping the pots/FSR to the globe application. Thanks for getting on my case about this. Now I have to hit the preview button, then the submit button.