Description:
In the first part of the lab, I connected my force resistor and photocell to my existing circuits and played around with different outcomes using blinking/fading LEDs. (you can still see the remnants of that with the pot in the photos - which I didn't use for the second part) Then after playing with processing a bit, I made a simpler circuit that allowed me to test the serial write function in Arduino. Thanks to Laura's updated code, I was able to troubleshoot some serial naming issues and get the Arduino board communicating with the computer.
At that point, I modified the Ball Paint code provided to take in a value from the Arduino board to influence the drawing of a square instead of a circle. I set the colors so that the squares would randomly be a range of yellow to red in order to show depth as the squares layered on top of each other. I also adjusted the base square so that with no input there was a dynamic background of small colored squares rather than just black. Once the design was satisfactory, I used the force resistor input to determine the size of the squares. With more force, the squares got larger and with less, they got smaller. I put the force resistor in between two small latex makeup squares, which work surprisingly well a force distributor for the finger.
One thing I wanted to do was interpret two different inputs (pot for speed of blinking/input to Processing and force resistor for size of square) but I couldn't figure out how to easily chain the inputs together and then unbind in Processing to take action. The internet was inconclusive regarding whether this is a hard thing to do or something that is relatively easy. I assume it has something to do with concatenating two separate values, passing as one through the serial connection and then breaking apart in Processing?
Items used for circuit:
- (1) Breadboard
- (1) 220 resistor
- (1) 10k resistor (for first part)
- (2) short connector wires
- (6) long wires
- (1) photocell (for first part)
- (1) Arduino Uno board
- (1) Red LED
- (1) Potentiometers (for first part)
- (3) Wires for the pot (ground, 5v, analog)
Arduino code used for Processing Vizualization:
/*
* AnalogInput
* by DojoDave <http://www.0j0.org>
*
* Turns on and off a light emitting diode(LED) connected to digital
* pin 13. The amount of time the LED will be on and off depends on
* the value obtained by analogRead(). In the easiest case we connect
* a potentiometer to analog pin 2.
*
* http://www.arduino.cc/en/Tutorial/AnalogInput */
int potPin = 4; // select the input pin for the potentiometer
/*int potPin2 = 4; // select second input pin for force resistor*/
int ledPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val/5); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val/5); // stop the program for some time
Serial.write(val);
}
Processing code used for visualization:
/*
* Arduino Ball Paint
* (Arduino Ball, modified 2008)
* ----------------------
*
* 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.
*
* Receives an ASCII number over the serial port,
* terminated with a carriage return (ascii 13) then newline (10).
*
* This matches what Arduino's " Serial.println(val)" function
* puts out.
*
* Created 25 October 2006, modified by Brian Murphy w/ TUI code (October 7, 2013)
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/
//Import Serial module
import processing.serial.*;
Serial port;
//Sets canvas
void setup() {
size(600,600);
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()[0], 9600);
}
//Starts drawing loop
void draw() {
}
// draws boxes using input from serial for "r"
void drawbox(int x, int y, int r) {
for (int i=0; i<100; i++ ) {
//fills with varying green value to create random colors from red->yellow
fill(255,random(255),0);
stroke(0);
rectMode(CENTER);
rect(x,y,r*2,r*2);
}
}
// 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);
println("val="+c);
int x = int(random(0,width));
int y = int(random(0,height));
//sizes up serial input value so that visible square appear even when input is 0
c += 5;
//draws box using random x,y coordinates and c for size of box
drawbox(x,y,c);
}
- Login to post comments