Beispiel #1
0
# import modules or classes for controlling components and code from code libraries
# import the PMA Ultrasonic Sensor class from the ptpma library (PMA = pi-top Maker Architecture)
# sleep lets us tell our components to wait (on or off) for a specified amount of time
from ptpma import PMAUltrasonicSensor, PMALightSensor, PMASoundSensor, PMAButton
from time import sleep

# name the component(s) and state which port(s) they are connected to
ultrasonic_sensor = PMAUltrasonicSensor("D4")
light_sensor = PMALightSensor("A2")
sound_sensor = PMALightSensor("A3")
caller = PMAButton("D5")

# the loop will return a constant distance reading
while True:
    if caller.is_pressed:
        print(ultrasonic_sensor.distance)
        sleep(0.1)
        print(light_sensor.reading)
        sleep(0.1)
        print(sound_sensor.reading)
        sleep(0.1)
from ptpma import PMALed, PMAButton, PMABuzzer, PMAUltrasonicSensor, PMALightSensor, PMASoundSensor, PMAPotentiometer
from time import sleep

gled = PMALed("D2")
yled = PMALed("D1")
rled = PMALed("D0")
button = PMAButton("D3")
buzz = PMABuzzer("D4")
us = PMAUltrasonicSensor("D5")
testrn = PMAButton("D6")
ls = PMALightSensor("A0")
ss = PMASoundSensor("A1")
select = PMAPotentiometer("A2")


def sswarn():
    if ss.reading < 30:
        gled.on()
        sleep(1)
        gled.off()
    if ss.reading > 30 and ss.reading < 75:
        yled.on()
        sleep(1)
        yled.off()
    if ss.reading > 75 and ss.reading < 150:
        rled.on()
        sleep(1)
        rled.off()
    if ss.reading > 150:
        rled.on()
        buzz.on()