Kissing a Frog!

Assignment: Sensing PART II: Force Sensitive Resistors and Photocells

Collaborators:

Assignment: Sensing PART II: Force Sensitive Resistors and Photocells
Collaborators:

Arduino Code:

 

/* Kissing Frog Force Input for Prince Creation mildy adapted by Hazel Onsrud

*  after:

* one pot fades one led

* modified version of AnalogInput

* by DojoDave <http://www.0j0.org>

* http://www.arduino.cc/en/Tutorial/AnalogInput

*/

int potPin = 2;   // select the input pin for the potentiometer

int ledPin = 9;   // select the pin for the LED

int val = 0;      // variable to store the value coming from the sensor

void setup() {

Serial.begin(9600);

pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT

}

 

void loop() {

val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024

Serial.println(val);

analogWrite(ledPin, val/4); // analogWrite can be between 0-255

delay(200);

}

 

 

Processing Code:

 

 

* I adapted the code to take serial imputs, as well as

* incorporating my mechanical FSR.

* This code notes how forceful a kiss the frog recieves and if forcefull

* enough the frog turns into a prince!

*

* (Modeled after Arduino Ball Paint which was after (Arduino Ball, modified))

* Draw balls randomly on the screen, size controlled by a device

* on a serial port.  Press space bar to clear screen, or any

* other key to generate fixed-size random balls.

* Created 25 October 2006

* copyleft 2006 Tod E. Kurt <tod@todbot.com

* http://todbot.com/

*

 

 

import processing.serial.*;

 

String portname = "COM4"; // or "COM5"

 

Serial port;

 

String buf="";

int cr = 13;  // ASCII return   == 13

int lf = 10;  // ASCII linefeed == 10

 

 

void setup() {

size(600,600);

frameRate(10);

smooth();

background(255);

noStroke();

port = new Serial(this, portname, 9600);

}

 

void draw() {

}

 

// display an image of a frog

void drawfrog(){

PImage img1;

img1 = loadImage("http://www.abc.net.au/science/scribblygum/March2001/img/f_GreenTreeFrog.jpg");

image(img1, 0, 0, width, height);

}

 

// display an image of an explosion

void drawpoof(){

PImage img1;

img1 = loadImage("http://grandepublishing.com/images/explosion.gif");

image(img1, 0, 0, width, height);

}

 

// display an image of a prince

void drawprince(){

PImage img1;

img1 = loadImage("http://www.arthursclipart.org/occupations/occupations/PRINCE.gif");

image(img1, 0, 0, width, height);

}

 

// called whenever serial data arrives

 

void serialEvent(Serial p) {

int c = port.read();

if (c != lf && c != cr) {

buf += char(c);

}

 

if (c == lf) {

println("c="+c);

println("buf="+buf);

int val = int(buf);

println("val="+val);

if (val >= 0 && val < 170){

drawfrog();

}

if (val >= 170 && val < 210){

drawpoof();

}

if (val >= 210 && val < 255){

drawprince();

}

buf = "";

//background(40,40,40);

}

}