Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Lab 5 - Who You Gonna Call?

Project Members: 
Isaac Salier-He...

Description

Something strange in the neighborhood? Who you gonna call?

Using input from a photocell under the roof of the car, this program instructs the (admittedly run-down) Ghostbusters-mobile to first play a rousing opening few bars of the film's theme song, then to flash the red and blue LEDs while sounding the siren.

The photocell is triggered when light drops below a certain level -- after all, ghost-hunting is a night-time job.

(Note: Originally, I had attempted to create a hamster water bottle that indicated (LED or Piezo) when it was low on water, but even though I had solved most of the mechanical problems involved, the FSR wasn't as sensitive as my plan required.)

Components

  • breadboard
  • 1 10k Ohm resistor, 2 220 Ohm resistors
  • wires (black for ground, green for input/output)
  • photocell
  • Piezo speaker
  • Arduino board
  • paper, colored pencils, tape (including the roll, which served as the front end of the car), cardboard box, plastic roof for the car
  • red and blue LEDs for the siren
  • lights around the car
  • rubber bands, gotta have rubber bands

Arduino Code

/*
*
* Isaac Salier-Hellendag
* October 3, 2007
* TUI Assignment 5
*
* Ghostbusters!
* When there's something strange in the neighborhood, or at least when the
* lights are turned off, ghouls and spooks come out and it's time for Bill Murray,
* Dan Aykroyd, and the other two dudes to get to work.
*
* The photocell responds when the light goes below a certain level, as the Piezo speaker
* plays the Ghostbusters theme, the LED lights flash as a siren, and the Piezo sounds
* the siren tones.
*
*/

int photocellPin = 0; // select the input pin for the potentiometer
int speakerPin = 7;
int redLedPin = 11;
int blueLedPin = 9;

int lightVal = 0;
int numFlashes = 25;
int sirenCount = 50;

byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody[] = "1f1p1f1p4b1p4g1p4a1p4f8p1d1p1d1p1d1p1d1p2c1p1d8p8p";
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// 10 20 30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;

void setup() {
pinMode(speakerPin, OUTPUT);
beginSerial(9600);
Serial.println("ready");
}

void loop() {
digitalWrite(speakerPin, LOW);

if(nightTime()) {
playMelody();
for(int i=0 ; i < numFlashes ; i++) {
flashSiren();
}
}

}

void flashSiren() {
analogWrite(redLedPin, 255);
for(int i=0 ; i < sirenCount ; i++) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tones[7]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[7]);
}
delay(500);
analogWrite(redLedPin, 0);
analogWrite(blueLedPin, 255);
for(int i=0 ; i < sirenCount ; i++) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tones[6]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[6]);
}
delay(500);
analogWrite(blueLedPin, 0);
}

void playTheme() {

}

boolean nightTime() {
lightVal = analogRead(photocellPin);
return (lightVal < 200);
}


void playMelody() {
digitalWrite(speakerPin, LOW);
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count*2 + 1]) {
digitalWrite(speakerPin,HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == 'p') {
// make a pause of a certain size
digitalWrite(speakerPin, 0);
delayMicroseconds(500);
}
}
}
}
}

Photos

Flickr: http://www.flickr.com/photos/46877131@N00/1487174245/

Video

YouTube: http://www.youtube.com/watch?v=FRKccuQbPV8


Powered by Drupal - Design by Artinet