Description
In this lab we experimented with the photo sensitive cells to adjust the voltate in the circuit board as well as using a force sensitive device to adjust the volate based on the pressure applied. We also made the Arduino board talk to the computer through the new Processing interface. I tried to make a variety of different displays work from the Processing interface, but eventually resorted to scowering the Processing website for examples of how to make a square work. I then used a funnel, a force plate (water bottle), and a volume constraint to magnify the force put on the pressure plate. This is analagous to how brakes work in a car.
Components Used:
1- Arduino Uno
1-Breadboard
1- LED
1- USB Cable
1- 10k Resistor
1- 220 Ohm Resistor
1-photosensitive sensor
1- force sensitive sensor
1-funnel
1- water bottle
1- dixie cup
Code:
Processing:
//Code to draw squares
-Justin Sampson
*/
import processing.serial.*;
// Change this to the portname your Arduino board
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
void setup() {
size(300,300);
frameRate(10);
smooth();
background(40,40,40);
noStroke();
/*
Run the code once with this print statement to see a list of available serial ports.
Make a note of the number next to the port you'd like to use
*/
println(Serial.list());
/* Once you know the number of the port you want to use Replace the "0" in the code below
with the port number. For instance, if you wanted to use port number 4 in the list, then
the code should say: port = new Serial(this, Serial.list()[4], 9600);
*/
port = new Serial(this, Serial.list()[4], 9600);
}
void draw() {
}
void keyPressed() {
if(key == ' ') {
background(40,40,40); // erase screen
}
else {
int x = int(random(0,width));
int y = int(random(0,height));
drawrect(x,y, 50);
}
}
// draw squares
void drawrect(int x, int y, int r) {
for (int i=0; i<100; i++ ) {
fill(255-i,i,240);
rect(x,y,r,r+40);
}
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
/* this print statement will allow you to see whether or not Processing can "hear" anything that
Arduino is sending. It should print all the changing values of the FSR or Photocell in your circuit
If nothing is printing, you probably picked the wrong serial port.
*/
println(c);
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
int val = int(buf);
println("val="+val);
int x = int(random(0,width));
int y = int(random(0,height));
drawrect(x,y,val);
buf = "";
background(40,40,40); // erase screen
}
}
Arduino:
/*
* 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 = 0; // 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...
}
- Login to post comments