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!


monster.growl()

Project Members: 
Laura Greig


Description

A monster helmet that growls at the push of a button.

Components

• Arduino Board
• Piezo speaker
• Red button

Arduino Code

/* A slighly modified version of:
 * Play Melody
 * -----------
 * (cleft) 2005 D. Cuartielles for K3
 */

int ledPin = 11;
int speakerOut = 7;               
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};  
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
//byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p";
//byte melody[] = "2c2d2e2a2g2a2c2d2c2f2e2f2e1b1c1d1a1e1d2e2f2e1b1e1a1p1a1p1b1p";
byte melody[] = "1a1p1b1p1a1b1a1b1d1c1p1c1d1c1d1e1p1f1d1e1f1e1f1e1p1e1d1c1b"; //wrote new melody
// 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 = 29;
int statePin = LOW;

void setup() {
 pinMode(ledPin, OUTPUT);
 pinMode(speakerOut, OUTPUT);
}

void loop() {

  for (count = 0; count < MAX_COUNT; count++) {
    statePin = !statePin;
    digitalWrite(ledPin, 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(speakerOut,HIGH);
          delayMicroseconds(random(tones[count2]-20, tones[count2]+20)); //randomized to add growly jitter
          digitalWrite(speakerOut, LOW);
          delayMicroseconds(random(100,2000)); //randomized to add growly jitter
        }
        if (melody[count*2 + 1] == 'p') {
          // make a pause of a certain size
          digitalWrite(speakerOut, 0);
          delayMicroseconds(500);
        }
      }
    }
  }
}

grrr
grrrgrrr


Powered by Drupal - Design by Artinet