Exemplo n.º 1
0
 def __init__(self, threshold=100):
     # Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
     self.sensor = ldt0028.LDT0028(0)
     self.average = 0
     self.state = 0
     self.text = 'Silence'
     self.threshold = threshold
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
def main():
    NUMBER_OF_SECONDS = 10
    SAMPLES_PER_SECOND = 50
    THRESHOLD = 100

    # Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
    sensor = ldt0028.LDT0028(0)

    # Read the signal every 20 milliseconds for 10 seconds
    print 'For the next', NUMBER_OF_SECONDS, 'seconds,', \
          SAMPLES_PER_SECOND, 'samples will be taken every second.\n'
    buffer = array.array('H')
    for i in range(0, NUMBER_OF_SECONDS * SAMPLES_PER_SECOND):
        buffer.append(sensor.getSample())
        time.sleep(1.0 / SAMPLES_PER_SECOND)

    # Print the number of times the reading was greater than the threshold
    count = 0
    for i in range(0, NUMBER_OF_SECONDS * SAMPLES_PER_SECOND):
        if buffer[i] > THRESHOLD:
            count += 1
    print sensor.name(), ' exceeded the threshold value of', \
            THRESHOLD, 'a total of', count, 'times,'
    print 'out of a total of', NUMBER_OF_SECONDS*SAMPLES_PER_SECOND, \
            'reading.\n'

    # Print a graphical representation of the average value sampled
    # each second for the past 10 seconds, using a scale factor of 15
    print 'Now printing a graphical representation of the average reading '
    print 'each second for the last', NUMBER_OF_SECONDS, 'seconds.'
    SCALE_FACTOR = 15
    for i in range(0, NUMBER_OF_SECONDS):
        sum = 0
        for j in range(0, SAMPLES_PER_SECOND):
            sum += buffer[i * SAMPLES_PER_SECOND + j]
        average = sum / SAMPLES_PER_SECOND
        stars_to_print = int(round(average / SCALE_FACTOR))
        print '(' + repr(int(
            round(average))).rjust(4) + ') |', '*' * stars_to_print

    # Delete the sensor object
    del sensor
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
import pyupm_mma7660 as accelerometerSensor

#######################################################################
#VARIABLES
#######################################################################
#Create the light sensor object using AIO pin 0
lightValue = grove.GroveLight(0)

#Create the loudness sensor object using AIO pin 1
loudnessValue = loudnessSensor.Loudness(1, 3.0)

#Create the temperature sensor object using AIO pin 2
#tempValue2 = mraa.Aio(2)

#Create the vibration sensor object using AIO pin 3
vibrationValue = vibrationSensor.LDT0028(3)
try:
    #Create the accelerometer sensor object using I2C 0
    accelerometerValue = accelerometerSensor.MMA7660(
        accelerometerSensor.MMA7660_DEFAULT_I2C_BUS,
        accelerometerSensor.MMA7660_DEFAULT_I2C_ADDR)
    print(accelerometerSensor.MMA7660_DEFAULT_I2C_BUS)
    #Place device in standby
    accelerometerValue.setModeStandby()

    #Place device into active mode
    accelerometerValue.setModeActive()

    ax = accelerometerSensor.new_floatp()
    ay = accelerometerSensor.new_floatp()
    az = accelerometerSensor.new_floatp()
Exemplo n.º 6
0
# 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 array
import pyupm_ldt0028 as ldt0028

NUMBER_OF_SECONDS = 10
SAMPLES_PER_SECOND = 50
THRESHOLD = 100

# Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
sensor = ldt0028.LDT0028(0)

# Read the signal every 20 milliseconds for 10 seconds
print 'For the next', NUMBER_OF_SECONDS, 'seconds,', \
      SAMPLES_PER_SECOND, 'samples will be taken every second.\n'
buffer = array.array('H')
for i in range(0, NUMBER_OF_SECONDS * SAMPLES_PER_SECOND):
    buffer.append(sensor.getSample())
    time.sleep(1.0/SAMPLES_PER_SECOND)

# Print the number of times the reading was greater than the threshold
count = 0
for i in range(0, NUMBER_OF_SECONDS * SAMPLES_PER_SECOND):
    if buffer[i] > THRESHOLD:
        count += 1
print sensor.name(), ' exceeded the threshold value of', \
 def get_actuator(self):
     return pyupm_ldt0028.LDT0028(self.pin)