Page 311 - 최강 아두이노 퍼스트 참고서
P. 311

digitalWrite(ledPin,  LOW);  //  turn  LED  OFF              playTone(0,  0);
                 delay(300);           if (pirState == HIGH){       // we have just turned off
                       Serial.println("Motion ended!");
                       // We only want to print on the output change, not state       pirState = LOW;
                     }
                   }
                 }
                 // duration in mSecs, frequency in hertz void playTone(long duration,
                 int freq) {     duration *= 1000;
                     int period = (1.0 / freq) * 1000000;     long elapsed_time = 0;
                 while         (elapsed_time        <          duration)
                 {                           digitalWrite(pinSpeaker,HIGH);
                 delayMicroseconds(period  /  2);                  digitalWrite(pinSpeaker,
                 LOW);         delayMicroseconds(period / 2);         elapsed_time +=
                 (period);
                     }
                 }


































                                                   311
   306   307   308   309   310   311   312   313   314   315   316