def initSound(): global mymic global threshContext mymic = upmMicrophone.Microphone(1) threshContext = upmMicrophone.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 print("Sound init")
def __init__(self): # Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0 self.piezo = ldt0028.LDT0028(0) # Create the light sensor object using AIO pin 1 self.light = grove.GroveLight(1) #led on D5 self.led = mraa.Gpio(5) self.led.dir(mraa.DIR_OUT) self.mic = upmMicrophone.Microphone(2) self.threshContext = upmMicrophone.thresholdContext() self.threshContext.averageReading = 0 self.threshContext.runningAverage = 0 self.threshContext.averagedOver = 2
def getSound(self): myMic = upmMicrophone.Microphone(int(self.port)) threshContext = upmMicrophone.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 buffer = upmMicrophone.uint16Array(128) len = myMic.getSampledWindow(2, 128, buffer) if len: thresh = myMic.findThreshold(threshContext, 30, buffer, len) #myMic.printGraph(threshContext) if (thresh): print "Threshold is ", thresh self.info["soundLevel"] = str(thresh) del myMic return self.info
def __init__(self): self.screen = pyupm_i2clcd.Jhd1313m1(6, 0x3E, 0x62) self.clearScreen() self.light = grove.GroveLight(2) self.mic = upmMicrophone.Microphone(1) self.threshContext = upmMicrophone.thresholdContext() self.threshContext.averageReading = 0 self.threshContext.runningAverage = 0 self.threshContext.averagedOver = 2 self.piezo = ldt0028.LDT0028(0) self.button = mraa.Gpio(3) self.button.dir(mraa.DIR_IN) self.buzzer = mraa.Gpio(6) self.buzzer.dir(mraa.DIR_OUT) self.buzzer.write(0)
def main(): # Attach microphone to analog port A0 myMic = upmMicrophone.Microphone(2) threshContext = upmMicrophone.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 # Infinite loop, ends when script is cancelled # Repeatedly, take a sample every 2 microseconds; # find the average of 128 samples; and # print a running graph of dots as averages while (1): buffer = upmMicrophone.uint16Array(128) len = myMic.getSampledWindow(2, 128, buffer) if len: thresh = myMic.findThreshold(threshContext, 30, buffer, len) myMic.printGraph(threshContext) if (thresh): print("Threshold is ", thresh) # Delete the upmMicrophone object del myMic
# The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import time import pyupm_mic as upmMicrophone # Attach microphone to analog port A0 myMic = upmMicrophone.Microphone(0) threshContext = upmMicrophone.thresholdContext() threshContext.averageReading = 0 threshContext.runningAverage = 0 threshContext.averagedOver = 2 # Infinite loop, ends when script is cancelled # Repeatedly, take a sample every 2 microseconds; # find the average of 128 samples; and # print a running graph of dots as averages while (1): buffer = upmMicrophone.uint16Array(128) len = myMic.getSampledWindow(2, 128, buffer) if len: thresh = myMic.findThreshold(threshContext, 30, buffer, len) myMic.printGraph(threshContext)
def get_actuator(self): return pyupm_mic.Microphone(self.pin)
# Author: Brendan Le Foll <*****@*****.**> # Copyright (c) 2014 Intel Corporation. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE import pyupm_mic mymic = pyupm_mic.Microphone(1) # careful this is an unitialised array with no bounds checking! x = pyupm_mic.uint16Array(3) mymic.getSampledWindow(100, 3, x)
def __init__(self, threshold=150): self.myMic = upmMicrophone.Microphone(1) self.state = 0 self.threshold = threshold