Tuesday, January 27, 2009

Valentine Rat

So now that Gordie & I had figured out how to create the switch for the flashing LEDs by following the Phys Comp Lab we decided to take a squeaky rubber rat and give him some flashy eyes.

We sped up the timing on the arduino code so that the eyes would flash quickly and switch fast. Here's the code Gordie & I came up with:


//declare variables:
int switchPin = 2; // digital input pin for a switch
int redlLedPin = 3; // diagital output pin for a LED
int redrLedPin = 4; // diagital output pin for a LED
int switchState = 0; // the state of the switch

void setup() {
pinMode(switchPin, INPUT); // set the switch pin to be an input
pinMode(redlLedPin, OUTPUT); // set the yellow pin to be an output
pinMode(redrLedPin, OUTPUT); // set the red pin to be an output
}

void loop() {
// read the switch input:
switchState = digitalRead(switchPin);

if (switchState == 0) {
// if the switch is open:
digitalWrite (redlLedPin, LOW); // turn on the left eye LED
digitalWrite (redrLedPin, LOW); // turn off the right eye LED
}
else {
// if the switch is closed:
digitalWrite (redlLedPin, HIGH); // turn on the left eye LED
delay (55); // wait for a little bit
digitalWrite (redrLedPin, HIGH); // turn on the right eye LED
delay (50); // wait for a little bit
digitalWrite (redlLedPin, LOW); // turn off the left eye LED
delay (50); // wait for a little bit
digitalWrite (redrLedPin, LOW); // turn off the right eye LED
delay (50); // wait for a little bit

}
}

And the final product was awesome!

The best part of this whole experience for me was learning how to use the soddering iron, here's Gordie getting a tutorial on it.



Gordie also talked about his freshman Biology class and having to dissect a rat that wasn't totally dead. So funny!

Monday, January 26, 2009

My First Stab at Phys Comp

So today I got started on projects in the Wonderful World of Physical Computing. My first step was to set up the Arduino and with a little help from Gordie + Nancy I finally figured out the driver situation and was well on my way!

My first task was setting up the breadboard and figuring out how to use the wire cutters but once I had that under my belt I was ready to roll. I then figured out how to make the LED's blink consecutively and switch between red + yellow.



Code:
// declare variables:
int switchPin = 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 switchState = 0; // the state of the switch

void setup () {
pinMode (switchPin, 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 output
}

void loop () {
// read the switch input:
switchState = digitalRead (switchPin);

if (switchState == 1) {
// if the switch is closed:
digitalWrite (yellowLedPin, HIGH); // turn off the yellow LED
digitalWrite (redLedPin, LOW); // turn off the red LED

}
else {
// if the switch is open:
digitalWrite(yellowLedPin, LOW); // turn off the yellow LED
digitalWrite(redLedPin, HIGH); // turn on the red LED
}
}