Catching up on PCOMP labs

I didn’t do these labs last week because I was busy with the Stupid Pet Trick, so I did them this morning.

I set up the servo motor:

[yframe url=’http://www.youtube.com/watch?v=Ht9TAp4V0B0′%5D

And then built the musical instrument.  I only had one FSR so I used different pressures to determine notes in order to play a melody.  My speaker was really quiet for some reason, but I could hear the melody.

Here’s the code I used:

#include “pitches.h”
int analValue;

void setup() {
Serial.begin(9600);
}

void loop() {
analValue = analogRead(A1);

int pitch = map(analValue, 0, 1000, 0, 3);
Serial.println(pitch);
Serial.println(analValue);

if (pitch == 0){
tone(8, NOTE_C4, 10);
} else if (pitch == 1) {
tone(8, NOTE_G3, 10);
} else if (pitch == 2) {
tone(8, NOTE_B3, 10);
}

}

Advertisements

Author: owen ribbit

poop

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s