def __init__(self): """Constructor""" threading.Thread.__init__(self) # Parent class constructor # GPIO setup self.unlock_pin = gpiozero.LED(TwiddleLock.unlock_pin) self.lock_pin = gpiozero.LED(TwiddleLock.lock_pin) self.service_btn = gpiozero.Button(TwiddleLock.service_btn_pin, bounce_time = 0.2, hold_time = 3) self.buzzer = gpiozero.Buzzer(TwiddleLock.buzzer_pin) # Potentiometer setup self.adc = Adafruit_MCP3008.MCP3008(mosi = TwiddleLock.spi_mosi_pin, miso = TwiddleLock.spi_miso_pin, clk = TwiddleLock.spi_clk_pin, cs = TwiddleLock.spi_ss_pin) self.potentiometer = Potentiometer(self.adc, TwiddleLock.adc_pot_channel) self.potentiometer.start() # LCD screen setup self.lcd = RPI_LCD.LCD(18, 17, 27, 22, 23, 24) # Variable setup self.log = [] self.dir = [] self.service_btn_held_last = False self.locked = True self.secure = True self.combo_in_progress = False self.to_close = False self.correct_combo = Combination([10, 20, 10], [-1, 1, -1])
def main(): led = gpiozero.LED(17) led.on() # light when app is running active_buzzer = gpiozero.Buzzer(20) button1 = gpiozero.Button(26) button2 = gpiozero.Button(19) button3 = gpiozero.Button(13) button4 = gpiozero.Button(6) button5 = gpiozero.Button(5) button6 = gpiozero.Button(22) button7 = gpiozero.Button(27) button1.when_pressed = active_buzzer.toggle button2.when_pressed = active_buzzer.on button3.when_pressed = active_buzzer.off button4.when_pressed = active_buzzer.beep button5.when_pressed = lambda: active_buzzer.beep(0.1, 0.1, 1) button6.when_pressed = lambda: active_buzzer.beep(0.3, 0.1, 1) running = True def close(): nonlocal running print("closing...") running = False button7.when_pressed = close while running: pass
def __init__(self, name, output_pins, input_pins, alarms=None, invert_on_off=False, **additional_params): self.name = name # Initialize the output interface if needed self.output_pins = output_pins self.invert_on_off = invert_on_off if output_pins[0] not in self.OUTPUTS: output = gpiozero.Buzzer(output_pins[0]) if self.invert_on_off: output.on, output.off = output.off, output.on # e.g. a particular shaker vibrates when it's "off" output.off() self.OUTPUTS[output_pins[0]] = output self.output = self.OUTPUTS[output_pins[0]] # Initialize the input interfaces if needed self.input_pins = input_pins self.toggle_pins = additional_params.get('toggle_pins', []) for pin in input_pins: if pin not in self.INPUTS: button = gpiozero.Button(pin) if pin in self.toggle_pins: button.when_pressed = lambda b: (self._record_button_press( b), self._toggle_when_alarm_off(b)) else: button.when_pressed = lambda b: self._record_button_press(b ) button.when_released = lambda b: self._record_button_release(b) self.INPUTS[pin] = {'button': button, 'events': []} self.alarms = alarms or {} self.alarm = {} self._reset_alarm() self.default_beep_on_length = additional_params.get( 'default_beep_on_length', 0.5) self.default_beep_off_length = additional_params.get( 'default_beep_off_length', 0.5) self.default_snooze_duration = additional_params.get( 'default_snooze_duration', 600) self.max_active_duration = additional_params.get( 'max_active_duration', 600) self.default_snooze_state = additional_params.get( 'default_snooze_state', 'off') self.running = True
class Pi: led = gpiozero.LED(17) active_buzzer = gpiozero.Buzzer(20) button1 = gpiozero.Button(26) button2 = gpiozero.Button(19) button3 = gpiozero.Button(13) button4 = gpiozero.Button(6) button5 = gpiozero.Button(5) button6 = gpiozero.Button(22) button7 = gpiozero.Button(27)
def main(*args): # Parse the arguments. args = parse_args(args) # Authenticate and bail early if requested. creds = auth() if (args.auth_only): return # Create an API client. cal = build('calendar', 'v3', credentials=creds) # Optionally mock out the lights. if args.mock_light: os.environ['GPIOZERO_PIN_FACTORY'] = 'mock' # Configure the stack. import gpiozero buzz = gpiozero.Buzzer(BUZZ_PIN) stack = gpiozero.LEDBoard(AWAY_PIN, BUSY_PIN, FREE_PIN) # Define a mapping between board LEDs and CalendarStatuses. led_mapping = dict([(CalendarStatus.AWAY, (1, 0, 0)), (CalendarStatus.BUSY, (0, 1, 0)), (CalendarStatus.FREE, (0, 0, 1))]) # Configure the stack to update periodically. check_delta = datetime.timedelta(seconds=args.check_interval) stack.source_delay = check_delta.total_seconds() stack.source = (led_mapping[cal_status] for cal_status in stream( status, cal, check_delta, args.day_start, args.day_end)) # Beep the buzzer once to indicate boot. buzz.beep(on_time=BEEP_TIME, n=1) # Wait for a signal, then quit. print('Waiting for signal...') signal.pause()
#!/usr/bin/python import gpiozero import time import argparse parser = argparse.ArgumentParser() parser.add_argument("--pulses", help="pulses to send", default=1, type=int) parser.add_argument("--gpio", help="gpio pin", default=14, type=int) parser.add_argument("--on", help="on time (ms)", default=250, type=int) parser.add_argument("--delay", help="delay time (ms)", default=250, type=int) parser.add_argument("--repeat", help="repetition groups", default=1, type=int) parser.add_argument("--interval", help="delay time (ms)", default=500, type=int) args = parser.parse_args() bell = gpiozero.Buzzer(args.gpio) for rep in range(args.repeat): if rep > 0: time.sleep(args.interval / 1000.0) for pulse in range(args.pulses): if pulse > 0: time.sleep(args.delay / 1000.0) bell.on() time.sleep(args.on / 1000.0) bell.off()
import gpiozero from signal import pause def func(): print("hi") button = gpiozero.Button(2) buzzer = gpiozero.Buzzer(3) button.when_pressed = buzzer.toggle pause()
import gpiozero import requests import json import io from googletrans import Translator trans = Translator() #komponentlerin bağlantı noktası buton_ing = gpiozero.Button(2) #buton_kapat = gpiozero.Button(3) buton_ss_al = gpiozero.Button(4) led_ing = gpiozero.LED(27) # buton ing aktif olması durumunda devamlı yanacak led_ss = gpiozero.LED(22) buzzer = gpiozero.Buzzer(17) #maskeleme için istenilen aralık enaz = np.array([50, 30, 30]) encok = np.array([120, 255, 110]) vid = cv2.VideoCapture(0) cv2.namedWindow("FotoAlmaislemi") img_counter = 0 #Foto sayisi while True: ret,frame = vid.read() #frame2 = cv2.resize(frame,(1920,1080)) # görüntünün daha iyi anlaşılması için "Maskeleme"işlemi;
if last_mode[sensor] != 'proximity': local_apds = APDS9960(i2c_bus) local_apds.enableProximitySensor() local_apds.setProximityGain(0) local_apds.setLEDDrive(0 if sensor.startswith('front') else 3) last_mode[sensor] = 'proximity' time.sleep(0.01) return apds.readProximity() ################## # Buzzer utility # ################## buzzer = gpio.Buzzer(13, active_high=False) def buzz(duration): buzzer.beep(on_time=duration, n=1) ################ # Leds utility # ################ leds = [gpio.LED(5), gpio.LED(12), gpio.LED(6)] def led_on(led_id): if not (1 <= led_id <= len(leds)):
oranzna.off() zelena.on() # semafor za avtomobile zelena = gpiozero.LED(17) rdeca = gpiozero.LED(22) oranzna = gpiozero.LED(27) # semafor za pešce zelena2 = gpiozero.LED(19) rdeca2 = gpiozero.LED(26) # gumb za pešce gumb = gpiozero.Button(24) # piezo aktivni brenčač zvok = gpiozero.Buzzer(18) # zelena za avtomobile, rdeča za pešce rdeca.off() oranzna.off() zelena.on() rdeca2.on() zelena2.off() # vsakokrat ko pešec pritisne gumb while True: if gumb.is_pressed: prehod()
import gpiozero as gpio from time import sleep import sys led = gpio.LED(17) pir = gpio.MotionSensor(4) buzzer = gpio.Buzzer(27) servo = gpio.AngularServo(22,min_angle=-90,max_angle=90) sensor = gpio.DistanceSensor(echo = 18, trigger = 13) def turnOn(): led.on() sleep(10) print('Light was on, it just turned off') def turnOff(): led.off() print('Light is now off') def servoMovement(angle): angle = int(angle) servo.angle = angle sleep(3 ) print('Servo Moved') def buzz(): buzzer.on() sleep(10) print('buzzzz') def noBuzz():
import time import gpiozero from signal import pause import datetime import picamera ####### GPIO Def ########### buzz=gpiozero.Buzzer(4) button1=gpiozero.Button(26) led1=gpiozero.LED(17) cam=picamera.PiCamera() ############################ led1.off() hold_time=2 cam.resolution = (1024, 768) def now(p): t = datetime.datetime.now() a = t.strftime('%d-%m-%Y, %H:%M:%S') if p == 0: return t elif p == 1: return a def take_picture(i,file): time.sleep(i) cam.capture(file) print('Click!')
aldis.off() zvok.off() def oddaj(zaporedje): for znak in zaporedje: prizgi() if znak == '.': time.sleep(enota) if znak == '-': time.sleep(3 * enota) ugasni() time.sleep(enota) zvok = gpiozero.Buzzer(4) aldis = gpiozero.LED(27) enota = 0.1 # privzeta enota je desetinka sekunde abeceda = { 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---',
import paho.mqtt.client as mqtt import gpiozero red = gpiozero.Buzzer(3) # The callback for when the client receives a CONNACK response from the server. def on_connect(client, userdata, flags, rc): print("Connected with result code "+str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. client.subscribe("/domo") # The callback for when a PUBLISH message is received from the server. def on_message(client, userdata, msg): print(msg.topic+" "+str(msg.payload)) if str(msg.payload) == "triggered": red.blink(n = 4, on_time=0.25, off_time=0.25) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.connect("localhost", 1883, 60) # Blocking call that processes network traffic, dispatches callbacks and # handles reconnecting. # Other loop*() functions are available that give a threaded interface and a # manual interface. client.loop_forever()
def __init__(self, gpio): self.buzzer = gpiozero.Buzzer(gpio) print(">> Buzzer Module started GPIO", gpio)