º» Á¦Ç°Àº ÀÛÀº »çÀÌÁîÀÇ ¸¶ÀÌÅ©·ÎÆù ¾Æ³¯·Î±× »ç¿îµå ¼¾¼ÀÔ´Ï´Ù. ¸ñ¼Ò¸®³ª ¹Ú¼ö¼Ò¸®, ³ëÅ©¼Ò¸® µîÀÇ ¼Ò¸®¸¦ ÁõÆøÇÏ¿© 2.7~5.5VÀÇ ¾Æ³¯·Î±× ½ÅÈ£·Î º¯È¯½ÃÄÑÁÖ¸ç, ¾ÆµÎÀ̳ë¿Í °°Àº ¸¶ÀÌÅ©·Î ÄÁÆ®·Ñ·¯º¸µå¸¦ ÅëÇØ ½ÅÈ£¸¦ ÀԷ¹ÞÀ» ¼ö ÀÖ½À´Ï´Ù.
const int sampleWindow = 250;
unsigned int knock;
int ledPin = 9;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
unsigned long start= millis();
unsigned int peakToPeak = 0;
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
while (millis() - start < sampleWindow)
{
knock = analogRead(0);
if (knock < 1024)
{
if (knock > signalMax)
{
signalMax = knock;
}
else if (knock < signalMin)
{
signalMin = knock;
}
}
}
peakToPeak = signalMax - signalMin;
double volts = (peakToPeak * 3.3) / 1024;
Serial.println(volts);
if (volts >=1.0)
{
digitalWrite(ledPin, HIGH);
delay(500);
Serial.println("Knock Knock");
}
else
{
digitalWrite(ledPin, LOW);
}
}
|