Tuesday, December 15, 2009

Microphone Circuits - Prototype #1

http://www.arch.columbia.edu/work/courses/visual-studies/f09-living-architecture/man-kei-sham?page=1

1.

inline void digitalPullup(byte pin, boolean b) { pinMode(pin, INPUT); digitalWrite(pin, b?HIGH:LOW); }
#if defined(__AVR_ATmega1280__)
inline void analogPullup(byte pin, boolean b) { digitalPullup(pin+54,b); }
#else
inline void analogPullup(byte pin, boolean b) { digitalPullup(pin+14,b); }
#endif

void setup() {
Serial.begin(9600);
pinMode(clearred, OUTPUT);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);

analogPullup(0, true); // enable the 20kOhm pull-up on analog pin 0
}

void loop() {
// read the analog input into a variable:
int analogValue = analogRead(0);
// print the result:
Serial.println(analogValue);
// wait 10 milliseconds for the analog-to-digital converter
// to settle after the last reading:
delay(200); //slow enough to examine the values. Yell registers higher than 500 at about 1023.
}


2.

potential processing code (with amplifier:LM386, an op-amp):

/*
* Monitor for sound sensor
*/

int potPin = 2; // select the input pin for sound sensor
int ledPin = 13; // select the pin for the LED
int val = 0;
int amp = 0;

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}

void loop() {
val = analogRead(potPin);
amp = (val >= 512) ? val - 512 : 512 - val;
if (amp > 100) {
digitalWrite(ledPin, HIGH);
delay(20);
}
else {
digitalWrite(ledPin, LOW);
}
}

3.

//This is the code we ended up using. We got it to run and we got the light to come on, but we couldn't get it to respond to the microphone.

#define cleared 13

inline void digitalPullup(byte pin, boolean b) { pinMode(pin, INPUT);
digitalWrite(pin, b?HIGH:LOW); }

#if defined(__AVR_ATmega1280__)
inline void analogPullup(byte pin, boolean b) { digitalPullup(pin+54,b); }

#else
inline void analogPullup(byte pin, boolean b) { digitalPullup(pin+14,b); }

#endif

void setup() {
Serial.begin(9600);
pinMode(cleared, OUTPUT);
//pinMode(red, OUTPUT);
//pinMode(green, OUTPUT);

analogPullup(0, true); // enable the 20kOhm pull-up on analog pin 0
}

void loop() {
// read the analog input into a variable:
int analogValue = analogRead(0);
// print the result:
Serial.println(analogValue);
digitalWrite(cleared, HIGH);
pinMode(cleared, OUTPUT);
// wait 10 milliseconds for the analog-to-digital converter
// to settle after the last reading:
delay(200); //slow enough to examine the values. Yell registers higher than 500 at about 1023.
}


Labels: , , ,


Comments:

Post a Comment





<< Home

This page is powered by Blogger. Isn't yours?