Thursday, September 25, 2008

Physical Computing Assignment 3 : Electronics

The voltage measuring lab was pretty straight up. I had previously soldered the power connector and pot.

The only unexpected behaviour i had was in step 4: I noticed that the LEDs varied in brightness. This was due to the fact that i used LEDs from different packages and they varied in expected volts. Also unexpected was when connecting a pot to LEDs in parallel: Here only the first LED lights up.

IMG_0158

IMG_0158

IMG_0158

IMG_0158

IMG_0158

Thursday, September 18, 2008

Observation - F Train

Taking the F-train back and forth to the city yesterday i attempted the observation exercise. It was difficult getting any sort of controlled data, but i'll average each trip:


F-Train - Carrol Street -> 42nd, 4pm - 4:30pm

16 unique riders engaging phone , most likely for text or other reasons
17 riders with headphones
3 riders playing some form of video game
1 rider reading an electronic book


F-Train - 42nd -> Carrol Street, 5:45pm - 6:15pm

21-26 unique riders engaging phone
22 riders with headphones
2 riders playing some form of video game

Physical Computing Assignment 2 : Analog Input

I began this lab by setting up the demo, which required first soldering the pot. Easy enough:

IMG_0158

To build the "luv-o-meter" i decided to use an ultrasonic range finder that i had previously attempted to get working w/ a PIC chip (w/ less success).

IMG_0161

With the arduino board it was fairly easy to read: I read one of the output pins on the range finder to the analog input. The stream of data is the time it takes the pulse from the range finder to bounce off an object and return to the sensor.

For the meter, I take this data and determine the magnitude within the max and min range, and divide this by the 6 readout LEDs, then display this on the scale:

IMG_0164

I'm not yet sure how this meter can demonstrate a user's sex appeal or love making prowess ... still working on this part.



-------------
Arduino Code:
-------------

int potPin = 5; // Analog input pin that the potentiometer is attached to
int val = 0;

int highWall = 70;
int lowWall = 32;

int bracket = (highWall - lowWall) / 6;

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);

pinMode(8, OUTPUT); // set the red LED pin to be an
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);

}

void loop() {

val = analogRead(potPin); // read the pot value

if (val > 0) {
val;
}

digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);

if (val < 2*bracket) {digitalWrite(8, HIGH);}
if (val < 3*bracket) {digitalWrite(9, HIGH);}
if (val < 4*bracket) {digitalWrite(10, HIGH);}
if (val < 5*bracket) {digitalWrite(11, HIGH);}
if (val < 6*bracket) {digitalWrite(12, HIGH);}
if (val < 7*bracket) {digitalWrite(13, HIGH);}

}

Tuesday, September 16, 2008

PComp : Week 1 : Combination Lock

For this lab, i decided to build a combination lock to try to get a little more familiar with programming for Arduino. I started by building a simple 3-button array:

Arduino

Arduino



The basic functionality is that a red LED is lit untill the 3-button code is attempted. On the first button entry, the LED is turned off. After 3 buttons are pushed, if the combination is correct (a simple array of the button order: button2, button3, button1), I turn on the greed LED. If not, I lite the red LED and the flow starts over.

Arduino

Arduino



Below is the Arduino code. The main functional problem i had was buttons occasionally registering twice. There are definitely more subtleties in programming w/ physical inputs versus the computer programming i am used to, which will require another round of debugging. I found that below worked as expected about 75% of the time.



// declare variables:
int switchPin1 = 6;
int switchPin2 = 5;
int switchPin3 = 2; // digital input pin for a switch

int yellowLedPin = 3; // digital output pin for an LED
int redLedPin = 4; // digital output pin for an LED

int pin1;
int pin2;
int pin3;

int count = 0;
int cleared = 1;
int totalPinCount = 0;
int pushed = 0;

int combination[] = {switchPin3, switchPin2, switchPin1};
int combinationIndex = 0;
int combinationLength = 3;
int hold = 0;

void setup() {

// open the serial port at 9600 bps:
Serial.begin(9600);

pinMode(switchPin1, INPUT); // set the switch pin to be an input
pinMode(switchPin2, INPUT); // set the switch pin to be an input
pinMode(switchPin3, INPUT); // set the switch pin to be an input

pinMode(yellowLedPin, OUTPUT); // set the yellow LED pin to be an output
pinMode(redLedPin, OUTPUT); // set the red LED pin to be an

digitalWrite(redLedPin, HIGH);
}


void loop() {

pin1 = digitalRead(switchPin1);
pin2 = digitalRead(switchPin2);
pin3 = digitalRead(switchPin3);

totalPinCount = pin1 + pin2 + pin3;

if (cleared == 1 && totalPinCount == 1)
{
cleared = 0;
digitalWrite(yellowLedPin, LOW);
digitalWrite(redLedPin, LOW);

if (pin1 == 1) {pushed = switchPin1;}
if (pin2 == 1) {pushed = switchPin2;}
if (pin3 == 1) {pushed = switchPin3;}

if (combination[combinationIndex] == pushed)
{

combinationIndex++;
if (combinationIndex >= combinationLength)
{
digitalWrite(yellowLedPin, HIGH);
}
}
else
{
combinationIndex = 0;
digitalWrite(redLedPin, HIGH);
Serial.print("* RESTART");

}
}


if (totalPinCount == 0)
{
cleared = 1;
}
}

PComp : Week 1 : Lab 2

Digital In/Out

This lab was again pretty straighforward, following the schematic. Only odd behavior was getting a USB power usage warning on my Mac. I have not seen this since the lab, so wonder if i had something incorrectly wired while getting this up and going.


Arduino


PComp : Week 1 : Lab 1

Setting up the breadboard

This was pretty straightforward once i purchased the "Diecimila" board. I started w/ the Arduino Mini board and a usb adapter board and was unable to load a script w/o errors, despite following the directions on the Arduino site. I plan to debug soon, but figured it would be worth going to the "Diecimila" to get up and going.