Page 321 - Tasarım Beceri Atölyeleri Öğretmen El Kitabı
P. 321
def detectSound(obj):
if (obj.resetMinMaxCounter == obj._observationWindowN):
extension = obj.staticMax - obj.staticMin
if (extension > 1000):
if obj.detectionEnabled:
obj.detectionEnabled = False
obj.activePumpkin = True
thread(scare)
obj.staticMax, obj.staticMin = -4096, 4096
obj.resetMinMaxCounter = 0
else:
c = obj.currentSample()
if (c > obj.staticMax):
obj.staticMax = c
elif (c < obj.staticMin):
obj.staticMin = c
obj.resetMinMaxCounter += 1
# set ‘detectSound’ as the function to be applied to the object at every sampling step
toishield.microphone.doEverySample(detectSound)
# start sampling at 1 millisecond (1 kHZ) with a window length of 50 so that
# the lowest detectable frequency is 20 Hz
toishield.microphone.startSampling(1,50,”raw”)
313