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 party(): #print("Party Time!") for i in range(10): gled.on() buzz.on() sleep(0.5) gled.off() yled.on() sleep(0.5) buzz.off() yled.off() rled.on() sleep(0.5) buzz.on() rled.off() sleep(0.3) buzz.off() sleep(0.1) gled.on()
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()
# 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, PMABuzzer, PMALed 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") test = PMAButton("D6") buzz = PMABuzzer("D7") led = PMALed("D0") # 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) if test.is_pressed: led.on() sleep(0.1) buzz.on() print(ultrasonic_sensor.distance) sleep(0.1) print(light_sensor.reading)