Пример #1
0
def sentry_check():
    # print("sentry check")
    x, y, z = cp.acceleration
    time.sleep(0.05)
    acc_x = abs(x/9.8)
    acc_y = abs(y/9.8)
    acc_z = abs(z/9.8)
    # print("acceleration = " + str(acc_x) + "," + str(acc_y) + "," + str(acc_z))
    temperature = cp.temperature
    # print("temperature = " + str(temperature) + " C")

    sentry = False

    # check if the trash can is shaked
    if cp.shake(shake_threshold=20):
        # this condition is due to critter
        print("Critter detected")
        print("acceleration = " + str(acc_x) + "," + str(acc_y) + "," + str(acc_z))
        sentry = True

    # check if the trash can is falling down
    # elif (acc_x > 0.5 and acc_x < 1) or (acc_y > 0.5 and acc_y < 1) and (acc_z > 0.7 and acc_z < 1.5):
        # this means the trash can is probably falling down
    #    print("The trash can is falling down...")
    #    print("acceleration = " + str(acc_x) + "," + str(acc_y) + "," + str(acc_z))
    #    sentry = True

    # check if ultrasonic sensor is still connected
    test = getTrashLevel()
    # check 3 more times
    counter = 0
    while counter < 3 and math.isnan(test):
        test = getTrashLevel()
        time.sleep(0.1)
        counter += 1
    if math.isnan(test):
        print("Ultrasonic sensor is not working anymore!!!!")
        sentry = True

    # check if the trash can is on fire
    if temperature > 48:  # checks if temp is 48+(celcius(degrees) of fire)
        print('the can is on fire')
        print("temperature = " + str(temperature) + " C")
        sentry = True

    #if cp.loud_sound(sound_threshold=250):
    #    print('animal attack')
    #    sentry = True

    if sentry:
        alarm()
"""This example flashes the little red LED when the Circuit Playground is shaken."""
from adafruit_circuitplayground import cp

while True:
    if cp.shake(shake_threshold=20):
        print("Shake detected!")
        cp.red_led = True
    else:
        cp.red_led = False
Пример #3
0
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

"""This example prints to the serial console when the Circuit Playground is shaken."""
from adafruit_circuitplayground import cp

while True:
    if cp.shake():
        print("Shake detected!")
Пример #4
0
#  Python code for Make Music with the Circuit Playground Express
#    by Rick Leander
#  Copyright (c) 2020 Rick Leander All rights reserved
#  Buy the book at https://www.amazon.com/author/rleander#
#
# shake or tap for tambourine sounds

from adafruit_circuitplayground import cp

# wave files

tap = 'hi_snare.wav'
shake = 'cymbal.wav'

# main loop

cp.detect_taps = 1
while True:
    if cp.tapped:
        cp.play_file(tap)
    if cp.shake(shake_threshold=12):
        cp.play_file(shake)
Пример #5
0
     display = False
 else:
     display = True
 if cp.touch_A1:
     dailytarget = 5000
 if cp.touch_A2:
     dailytarget = 10000
 if cp.touch_A3:
     dailytarget = 15000
 if cp.touch_A4:
     dailytarget = 20000
 if cp.touch_A5:
     dailytarget = 25000
 if cp.touch_A6:
     dailytarget = 30000
 if cp.shake(10):
     steps = steps + 1
 values = [(0, 0, 0)] * 10
 stepprogressled = steps % 10
 if steps < dailytarget:
     for i in range(0, steps * 10 / dailytarget):
         values[i] = (30, 0, 0)
 values[stepprogressled] = (0, 0, 30)
 if is_light_low() and light == True:
     update_low_light_values(values)
 if cp.button_a:
     if light == True:
         light = False
     else:
         light = True
 if display == False:
Пример #6
0
    last10.pop(0)
    avg10 = sum(last10) / 10

    # moving average n=50, very smooth
    last50.append(z)
    last50.pop(0)
    avg50 = sum(last50) / 50

    # If the difference between the moving average of the last 10 points and the moving average of
    # the last 50 points is greater than 1 m/s^2, this is true
    if avg10 - avg50 > 1:
        if consecutive_triggers > 3:  # Is true when avg10-avg50 > 1m/s^2 at least 3 times in a row
            # Detects shake. Due to the very low shake threshold, this alone would have very low
            # specificity. This was mitigated by having it only run when the acceleration
            # difference is greater than 1 m/s^2 at least 3 times in a row.
            if not cp.shake(shake_threshold=10):
                # Set brightness to max, timestamp when it was set to max, and set light_on to true
                cp.pixels.brightness = 1
                start = time.monotonic()
                light_on = True
        consecutive_triggers += 1  # increase it whether or not the light is turned on

    # light_on variable is for short circuiting. Not really necessary, just makes things run faster
    elif not light_on or time.monotonic() - start > 0.4:
        # Sine wave used for the color breathing effect.
        # Max brightness can be adjusted with the coefficient.
        cp.pixels.brightness = abs(math.sin(brightness)) * 0.5
        brightness += 0.05
        consecutive_triggers = 0
        light_on = False
Пример #7
0
from adafruit_circuitplayground import cp

while True:
    if cp.shake(50):
        print("Hard shake Detected")
        cp.pixels.fill((255, 0, 0))
        cp.play_tone(440, 10.0)

Пример #8
0
import random

brightness = 25


def dice():
    roll = (random.randint(1, 6))  #create randomization here
    if (roll == 1):
        cp.pixels[1] = (brightness, 0, 0)
    if (roll == 2):
        cp.pixels[2] = (brightness, 0, 0)
    if (roll == 3):
        cp.pixels[3] = (brightness, 0, 0)
    if (roll == 4):
        cp.pixels[4] = (brightness, 0, 0)
    if (roll == 5):
        cp.pixels[5] = (brightness, 0, 0)
    if (roll == 6):
        cp.pixels[6] = (brightness, 0, 0)

    time.sleep(2.0)
    cp.pixels.fill((0, 0, 0))


while True:
    if cp.shake():  #use the shake example code here
        dice()
        cp.red_led = True

    else:
        cp.red_led = False