def __init__(self, player): """Initalise UI""" self.player = player # Setup button inputs self.input_up = gpiozero.DigitalInputDevice(pin="GPIO40", pull_up=True) self.input_down = gpiozero.DigitalInputDevice(pin="GPIO41", pull_up=True) self.input_enter = gpiozero.DigitalInputDevice(pin="GPIO42", pull_up=True) # Setup internal state self.page = Page.FRONT # Player event callbacks self.player.bind_to_playing( self.player_playing_event) # Player "playing" callback self.player.bind_to_not_playing( self.player_not_playing_event) # Player "not playing" callback # Front page variables self.file_name = '' self.file_scroll = 0 self.scroll_timer = None # Init screen oled.clear_DDRAM() oled.set_DDRAM_addr(0x00) oled.write_string_DDRAM('NOTHING PLAYING')
def setup_cb(pin,mode): #print("pin=%d,status=%d" %(pin,) # do gpio setup if mode == "out": try: led = GPIO.LED(pin) self.add_digital_hw_pin(pin, None, gpioOut_h, led) logging.getLogger().debug(str(pin)+ str(mode)) except: pass if mode == "in": print(pull) if pull=="up": button = GPIO.DigitalInputDevice(pin, pullup=True) elif pull=="down": button = GPIO.DigitalInputDevice(pin, pullup=False) elif pull=="button": button = GPIO.Button(pin) else: button = GPIO.InputDevice(pin) self.add_digital_hw_pin(pin, gpioRead_h, None, button) # note the gpiozero button / led objects are payload as "state" logging.getLogger().debug(str(pin)+ str(mode))
def __init__(self, gpio_interface, encoder_pin_1, encoder_pin_2): self.gpio_interface = gpio_interface self.encoder_pin_1 = encoder_pin_1 self.encoder_pin_2 = encoder_pin_2 if self.gpio_interface == USE_RPI_GPIO: status.is_rpi_gpio_used = True RPi.GPIO.setmode(RPi.GPIO.BCM) RPi.GPIO.setwarnings(False) RPi.GPIO.setup(encoder_pin_1, RPi.GPIO.IN) RPi.GPIO.setup(encoder_pin_2, RPi.GPIO.IN) RPi.GPIO.setup(encoder_pin_1, RPi.GPIO.IN, RPi.GPIO.PUD_UP) RPi.GPIO.setup(encoder_pin_2, RPi.GPIO.IN, RPi.GPIO.PUD_UP) RPi.GPIO.add_event_detect(encoder_pin_1, RPi.GPIO.FALLING, callback=self.callback, bouncetime=BOUNCE_TIME) elif self.gpio_interface == USE_RPI_ZERO: self.encoder_pin_1_device = gpiozero.DigitalInputDevice( encoder_pin_1, pull_up=True, bounce_time=BOUNCE_TIME / 1000) self.encoder_pin_2_device = gpiozero.DigitalInputDevice( encoder_pin_2, pull_up=True, bounce_time=BOUNCE_TIME / 1000) self.encoder_pin_1_device.when_deactivated = self.callback elif self.gpio_interface == USE_PI_GPIO: if not utils.is_process_running('pigpiod'): log(ERROR, 'Encoder: pigpiod process not started') os._exit(3) self.level_encoder_1 = 0 self.level_encoder_2 = 0 self.last_event_gpio = None self.pigpio = pigpio.pi() self.pigpio.set_mode(encoder_pin_1, pigpio.INPUT) self.pigpio.set_mode(encoder_pin_2, pigpio.INPUT) self.pigpio.set_pull_up_down(encoder_pin_1, pigpio.PUD_UP) self.pigpio.set_pull_up_down(encoder_pin_2, pigpio.PUD_UP) self.pigpio.callback(encoder_pin_1, pigpio.EITHER_EDGE, self.callback2) self.pigpio.callback(encoder_pin_2, pigpio.EITHER_EDGE, self.callback2) self.counter = 0
def __init__(self, card_reader, lcd): # Set up basic values threading.Thread.__init__(self) self.card_reader = card_reader self.lcd = lcd self.SW0 = gpiozero.DigitalInputDevice(23, pull_up=True) self.SW1 = gpiozero.DigitalInputDevice(24, pull_up=True) self.SW2 = gpiozero.DigitalInputDevice(25, pull_up=True) self.shutdown_btn = gpiozero.Button(8) self.b_led = gpiozero.LED(22)
def __init__(self, gpio_interface, encoder_pin_1, encoder_pin_2): self.gpio_interface = gpio_interface self.encoder_pin_1 = encoder_pin_1 self.encoder_pin_2 = encoder_pin_2 if self.gpio_interface == const.USE_RPI_GPIO: RPi.GPIO.setmode(RPi.GPIO.BCM) RPi.GPIO.setwarnings(False) RPi.GPIO.setup(encoder_pin_1, RPi.GPIO.IN) RPi.GPIO.setup(encoder_pin_2, RPi.GPIO.IN) RPi.GPIO.add_event_detect(encoder_pin_1, RPi.GPIO.FALLING, callback=self.callback, bouncetime=BOUNCE_TIME) elif self.gpio_interface == const.USE_RPI_ZERO: self.encoder_pin_1_device = gpiozero.DigitalInputDevice( encoder_pin_1, bounce_time=BOUNCE_TIME / 1000) self.encoder_pin_2_device = gpiozero.DigitalInputDevice( encoder_pin_2, bounce_time=BOUNCE_TIME / 1000) self.encoder_pin_1_device.when_deactivated = self.callback elif self.gpio_interface == const.USE_PI_GPIO: self.level_encoder_1 = 0 self.level_encoder_2 = 0 self.last_event_gpio = None self.pigpio = pigpio.pi() self.pigpio.set_mode(encoder_pin_1, pigpio.INPUT) self.pigpio.set_mode(encoder_pin_2, pigpio.INPUT) self.pigpio.set_pull_up_down(encoder_pin_1, pigpio.PUD_UP) self.pigpio.set_pull_up_down(encoder_pin_2, pigpio.PUD_UP) self.pigpio.callback(encoder_pin_1, pigpio.EITHER_EDGE, self.callback2) self.pigpio.callback(encoder_pin_2, pigpio.EITHER_EDGE, self.callback2) self.counter = 0
def __init__(self, pinA, pinB, cwCallback, ccwCallback): self.btnA = g0.DigitalInputDevice(pinA, pull_up=False, bounce_time=0.05) self.btnA.when_activated = self.on_turn self.btnA.when_deactivated = self.on_turn self.btnB = g0.DigitalInputDevice(pinB, pull_up=False, bounce_time=0.05) self.btnB.when_activated = self.on_turn self.btnB.when_deactivated = self.on_turn self.lastState = self.get_state_code() self.onCW = cwCallback self.onCCW = ccwCallback
def CarTrans(factory): # Purpose: Check carriage for vacuum # If no vacuum return false # If vacuum return true # Assume: None # End: Outputs if the phone is on the carriage # Input: factory (IP address) # Output: True = vacuum # False = no vacuum # Set Pi pin for reading carriage vacuum transducer voltage digitally CarTrans = gpiozero.DigitalInputDevice(7, pull_up=True, bounce_time=None, pin_factory=factory) # Begin reading voltage CarTrans.on() # If vacuum return True else return False if CarTrans.value == 0: return True else: return False
def __init__(self, clk_pin, dt_pin, overflow=None, min_val=None, max_val=None): self.clk = gpiozero.DigitalInputDevice(clk_pin) self.dt = gpiozero.DigitalInputDevice(dt_pin) self.clk_last_value = self.clk.value self.dt_last_value = self.dt.value self.position = 0 self.last_position = 0 self.last_change_time = int(time.time()) self.overflow = overflow self.min_val = min_val self.max_val = max_val
def __init__(self, player): """Initalise I/O""" try: # Setup the MCLK out of GPIO 4 for DAC call([ "/home/pi/XTEC-PiPlayer/minimal_clk/minimal_clk", "19.23M", "-q" ]) self.player = player self.input_1 = gpiozero.DigitalInputDevice(pin="GPIO16", pull_up=True) self.input_2 = gpiozero.DigitalInputDevice(pin="GPIO17", pull_up=True) self.input_1.when_activated = self.input_1_active self.input_1.when_deactivated = self.input_1_inactive self.input_2.when_activated = self.input_2_active self.input_2.when_deactivated = self.input_2_inactive self.output_1 = gpiozero.DigitalOutputDevice(pin="GPIO12", initial_value=False) self.output_2 = gpiozero.DigitalOutputDevice(pin="GPIO13", initial_value=False) self.player.bind_to_playing( self.player_playing_event) # Player "playing" callback self.player.bind_to_not_playing( self.player_not_playing_event) # Player "not playing" callback except Exception as ex: print('Digital I/O: Error starting: ' + str(ex)) # Check boot options try: config = configparser.ConfigParser() config.read(config_path) if config['MP2']['output1'] == 'on_boot': self.output_1.on() if config['MP2']['output1'] == 'pulse_boot': self.output_1.blink() if config['MP2']['output2'] == 'on_boot': self.output_2.on() if config['MP2']['output2'] == 'pulse_boot': self.output_2.blink() except Exception as ex: print('Digital I/O: Player play error: ' + str(ex))
def setup(self, port, direction): try: p = hal.GPIOActor.getPin(self, port) if str(p) in self.Pins: gpio = self.Pins[str(p)] gpio.close() self.Pins[str(p)] = None if direction == 'in': self.Pins[str(p)] = gpiozero.DigitalInputDevice(p) if direction == 'out': self.Pins[str(p)] = gpiozero.DigitalOutputDevice(p) if direction == 'tristate': self.Pins[str(p)] = gpiozero.DigitalInputDevice(p) return True except BaseException as e: logging.debug("Exception:" + str(e)) return False
def configure_digital_inputs(configured_devices, input_devices): digital_inputs = pull_end_devices('digital', input_devices, 'input') for gpio in digital_inputs: try: configured_devices[gpio['id']] = gpiozero.DigitalInputDevice(gpio['pin']) except gpiozero.GPIOPinInUse: logging.error('Pin %s is already in use and cannot be assigned to %s!', gpio['pin'], gpio['name'])
def __init__(self, pin, conversion_factor=CONVERSION_FACTOR): """See class docstring for full details.""" self.pin = pin self.conversion_factor = conversion_factor self.count = 0 self.count_times = [] self.device = gpiozero.DigitalInputDevice(pin=self.pin, pull_up=True) self.device.when_activated = self._count self.start_time = time.monotonic()
def __init__(self, pin, max_counts=None, gpio_kwargs=None): self._gpio_kwargs = {} if gpio_kwargs is None else gpio_kwargs self._gpio_kwargs["pin"] = pin self._count_times = collections.deque(maxlen=max_counts) self._gpio_device = gpiozero.DigitalInputDevice(**gpio_kwargs) self._gpio_device.when_activated = self._count self.start_time = time.monotonic()
def __init__(self, DO_DIRECTION_PIN, DO_RESET_PIN, DI_FAULT_PIN, ARGS): self.REG = { # AMIS-30543 Registers 'WR': 0x00, 'CR0': 0x01, 'CR1': 0x02, 'CR2': 0x03, 'CR3': 0x09, 'SR0': 0x04, 'SR1': 0x05, 'SR2': 0x06, 'SR3': 0x07, 'SR4': 0x0A } self.CMD = { # AMIS-30543 Command constants 'READ': 0x00, 'WRITE': 0x80 } self.dirctrl = ARGS[0] self.pwmf = ARGS[1] self.pwmj = ARGS[2] self.sm = ARGS[3] self.mult = ARGS[4] self.dist = ARGS[5] self.step = ARGS[6] self.VAL = { 'WR': 0b00000000, # no watchdog 'CR0': 0b00010111 | self.sm, # & 2.7 A current limit 'CR1': 0b00000000 | self.dirctrl | self.pwmf | self.pwmj, # & step on rising edge & fast slopes 'CR2': 0b00000000, # motor off & no sleep & SLA gain @ 0.5 & SLA no transparent 'CR3': 0b00000000 #, # no extended step mode #'dist': self.dist, #'step': self.step } # InitGPIO PWM.setup(5, 0) # 5 us pulse_incr, 0 delay_hw PWM.init_channel(0, 3000) # DMA channel 0, 3000 us subcycle time self.DO_RESET = gpiozero.DigitalOutputDevice(DO_RESET_PIN) self.DO_DIRECTION = gpiozero.DigitalOutputDevice(DO_DIRECTION_PIN) self.DI_NO_FAULT = gpiozero.DigitalInputDevice(DI_FAULT_PIN) self.spi = SpiDev() self.spi.open(0, 0) self.spi.max_speed_hz = 1000000 self.RegisterSet()
def worker(): pir = gpiozero.DigitalInputDevice(5) counter = 1 while True: pir.wait_for_active camera = PiCamera() camera.resolution = (1024, 768) camera.capture('static/image_{:d}.jpg'.format(counter)) camera.close() counter += 1 time.sleep(10) return
def door_status(): #### need to come up with a way to check if the pin has already been set #if not door1: #try: #gpiozero.DigitalInputDevice(7).close() door1 = gpiozero.DigitalInputDevice(7, True, None) response = "The Value is " + str(door1.value) #except: # response = "The Value is " + str(door1.value) templateData = {'title': 'Door Status' + str(door1), 'response': response} return render_template('door.html', **templateData)
import gpiozero SPEED = 0.25 robot = gpiozero.Robot(left=(17, 18), right=(27, 22)) left = gpiozero.DigitalInputDevice(9) right = gpiozero.DigitalInputDevice(11) while True: if (left.is_active == True) and (right.is_active == True): robot.forward(SPEED) elif (left.is_active == False) and (right.is_active == True): robot.right(SPEED) elif (left.is_active == True) and (right.is_active == False): robot.left(SPEED) else: robot.stop()
def __init__(self, SORT, DEVICE_TYPE, PIN): super().__init__(SORT, DEVICE_TYPE, PIN) self.gpo = gpiozero.DigitalInputDevice()
import gpiozero import sys robot = gpiozero.Robot(left=(26, 16), right=(5, 6)) lefts = gpiozero.DigitalInputDevice(17) rights = gpiozero.DigitalInputDevice(27) leftend = gpiozero.DigitalInputDevice(22) rightend = gpiozero.DigitalInputDevice(23) robot.right() while True: if (lefts.is_active == True) and (rights.is_active == True): robot.stop() break else: continue sys.exit()
import gpiozero from gpiozero import Buzzer import time buzzer = Buzzer(26) TRIG=12 ECHO=13 maxTime=0.04 trigger = gpiozero.OutputDevice(TRIG) echo = gpiozero.DigitalInputDevice(ECHO) robot = gpiozero.Robot(left=(17,18), right=(27,22)) def get_distance(trigger, echo): trigger.on() time.sleep(0.00001) trigger.off() pulse_start = time.time() pulse_end = time.time() timeout = pulse_end + maxTime while echo.is_active == False and pulse_start < timeout: pulse_start = time.time() while echo.is_active == True and pulse_end < timeout: pulse_end = time.time() pulse_duration = pulse_end - pulse_start
from signal import pause import atexit import gpiozero from gpiozero.tools import scaled, negated robot = gpiozero.Robot(left=(27, 17), right=(24, 23)) left_obstacle_sensor = gpiozero.DigitalInputDevice(13) right_obstacle_sensor = gpiozero.DigitalInputDevice(26) # Ensure it will stop atexit.register(robot.stop) robot.right_motor.source = scaled(left_obstacle_sensor, -1, 1) robot.left_motor.source = scaled(right_obstacle_sensor, -1, 1) pause()
import datetime import gpiozero #app = Flask(__name__) robot = gpiozero.Robot(left=(26, 16), right=(5, 6)) leftend = gpiozero.DigitalInputDevice(17) center = gpiozero.DigitalInputDevice(27) rightend = gpiozero.DigitalInputDevice(22) backl = gpiozero.DigitalInputDevice(23) rightl = gpiozero.DigitalInputDevice(19) while True: if (center.is_active == True) and (leftend.is_active == False) and (rightend.is_active == False): print("forward") robot.forward() elif (leftend.is_active == False) and (rightend.is_active == True): robot.right() print("right") elif (leftend.is_active == True) and (rightend.is_active == False): robot.left() print("left")
left_press = False right_press = False left_max = False right_max = False run_sequence = True t_Left_start = 0 t_Left_end = 0 t_Left = 0 t_Right_start = 0 t_Right_end = 0 t_Right = 0 t_Max = 1000 #Maximum Time between ticks in milliseconds left_button = gpiozero.DigitalInputDevice(17) right_button = gpiozero.DigitalInputDevice(27) print("Choose Your Direction! Press both buttons simultaneously to finish\n") while run_sequence == True: if left_press == True and (int(round(time.time() * 1000)) - t_Left_start) > t_Max: left_max = True if right_press == True and (int(round(time.time() * 1000)) - t_Right_start) > t_Max: right_max = True if left_button.value == 1 and left_press == True and right_button.value == 1 and right_press == True: print("Direction Control Completed\n")
def callButtons(): left_press = False right_press = False left_max = False right_max = False run_sequence = True t_Left_start = 0 t_Left_end = 0 t_Left = 0 t_Right_start = 0 t_Right_end = 0 t_Right = 0 t_Max = 1000 #Maximum Time between ticks in milliseconds left_button = gpiozero.DigitalInputDevice(17) right_button = gpiozero.DigitalInputDevice(27) print("Choose Your Direction! Press both buttons simultaneously to finish\n") while run_sequence == True: if left_press == True and (int(round(time.time()*1000)) - t_Left_start) > t_Max: left_max = True if right_press == True and (int(round(time.time()*1000)) - t_Right_start) > t_Max: right_max = True if left_button.value == 1 and left_press == True and right_button.value == 1 and right_press == True: client.publish(topicName, playerName + ",endButtons", qos=1) print("Direction Control Completed\n") run_sequence = False return elif left_button.value == 1 and left_press == False: #print("Left Button Pressed\n") left_press = True t_Left_start = int(round(time.time()*1000)) elif left_max == True or (left_button.value == 0 and left_press == True): left_press = False left_max = False t_Left_end = int(round(time.time()*1000)) t_Left = t_Left_end - t_Left_start #print("Left Button Released, Time: {}\n".format(t_Left)) client.publish(topicName, playerName + ",turn,left," + str(t_Left), qos=1) print("turn,left,{}\n".format(t_Left)) elif right_button.value == 1 and right_press == False: #print("Right Button Pressed\n") right_press = True t_Right_start = int(round(time.time()*1000)) elif right_max == True or (right_button.value == 0 and right_press == True): right_press = False right_max = False t_Right_end = int(round(time.time()*1000)) t_Right = t_Right_end - t_Right_start #print("Right Button Released, Time: {}\n".format(t_Right)) client.publish(topicName, playerName + ",turn,right," + str(t_Right), qos=1) print("turn,right,{}\n".format(t_Right))
vlc.Media(sconfig['SW2D']['C']), vlc.Media(sconfig['SW2D']['D']), vlc.Media(sconfig['SW2D']['E']), vlc.Media(sconfig['SW2E']['A']), vlc.Media(sconfig['SW2E']['B']), vlc.Media(sconfig['SW2E']['C']), vlc.Media(sconfig['SW2E']['D']), vlc.Media(sconfig['SW2E']['E']) ] # Setup controls enc_a = gpiozero.Button(17) # Rotary encoder pin A connected to GPIO17 enc_b = gpiozero.Button(27) # Rotary encoder pin B connected to GPIO27 enc_c = gpiozero.Button(22) # Rotary encoder push button connected to GPIO22 sw1_a = gpiozero.DigitalInputDevice(10, pull_up=True) sw1_b = gpiozero.DigitalInputDevice(9, pull_up=True) sw1_c = gpiozero.DigitalInputDevice(11, pull_up=True) sw2_a = gpiozero.DigitalInputDevice(7, pull_up=True) sw2_b = gpiozero.DigitalInputDevice(8, pull_up=True) sw2_c = gpiozero.DigitalInputDevice(25, pull_up=True) # *** Definitions *** # Event handler definitions def enc_a_rising(): # Pin A event handler if enc_b.is_pressed: eventq.put(
def __init__(self, name, gpio_interface, encoder_pin_1, encoder_pin_2, encoder_pin_press): log( INFO, 'Setting up {} encoder: {} / {} / {}'.format( name, encoder_pin_1, encoder_pin_2, encoder_pin_press)) self.name = name self.gpio_interface = gpio_interface self.encoder_pin_1 = encoder_pin_1 self.encoder_pin_2 = encoder_pin_2 self.encoder_pin_press = encoder_pin_press if self.gpio_interface == USE_RPI_GPIO: RPi.GPIO.setmode(RPi.GPIO.BCM) RPi.GPIO.setwarnings(False) RPi.GPIO.setup(encoder_pin_1, RPi.GPIO.IN) RPi.GPIO.setup(encoder_pin_2, RPi.GPIO.IN) if self.encoder_pin_press is not None: RPi.GPIO.setup(encoder_pin_press, RPi.GPIO.IN) RPi.GPIO.setup(encoder_pin_1, RPi.GPIO.IN, RPi.GPIO.PUD_UP) RPi.GPIO.setup(encoder_pin_2, RPi.GPIO.IN, RPi.GPIO.PUD_UP) if self.encoder_pin_press is not None: RPi.GPIO.setup(encoder_pin_press, RPi.GPIO.IN, RPi.GPIO.PUD_UP) RPi.GPIO.add_event_detect(encoder_pin_1, RPi.GPIO.FALLING, callback=self.callback, bouncetime=self.BOUNCE_TIME) elif self.gpio_interface == USE_RPI_ZERO: self.encoder_pin_1_device = gpiozero.DigitalInputDevice( encoder_pin_1, pull_up=True, bounce_time=self.BOUNCE_TIME / 1000) self.encoder_pin_2_device = gpiozero.DigitalInputDevice( encoder_pin_2, pull_up=True, bounce_time=self.BOUNCE_TIME / 1000) if self.encoder_pin_press is not None: self.encoder_pin_press_device = gpiozero.DigitalInputDevice( encoder_pin_press, pull_up=True, bounce_time=self.BOUNCE_TIME / 1000) self.encoder_pin_1_device.when_deactivated = self.callback elif self.gpio_interface == USE_PI_GPIO: self.level_encoder_1 = 0 self.level_encoder_2 = 0 self.last_event_gpio = None self.pigpio = pigpio.pi() self.pigpio.set_mode(encoder_pin_1, pigpio.INPUT) self.pigpio.set_mode(encoder_pin_2, pigpio.INPUT) if self.encoder_pin_press is not None: self.pigpio.set_mode(encoder_pin_press, pigpio.INPUT) self.pigpio.set_pull_up_down(encoder_pin_1, pigpio.PUD_UP) self.pigpio.set_pull_up_down(encoder_pin_2, pigpio.PUD_UP) if self.encoder_pin_press is not None: self.pigpio.set_pull_up_down(encoder_pin_press, pigpio.PUD_UP) self.pigpio.callback(encoder_pin_1, pigpio.EITHER_EDGE, self.callback2) self.pigpio.callback(encoder_pin_2, pigpio.EITHER_EDGE, self.callback2) self.counter = 0 return
def __init__(self, handset_pin=22, dummy_mode=False, dial_mode='buttons'): if dummy_mode: print("Using the dummy mode pins") from gpiozero.pins.mock import MockFactory gpiozero.Device.pin_factory = MockFactory() elif dial_mode == 'buttons': print("Using button dialling!") self.ping_buttons = self.button_dialling # The buttons are separated into groups. # These are one side of the buttons, which will have a voltage applied self.grpA_pin = gpiozero.DigitalOutputDevice(pin=12, initial_value=False) self.grpB_pin = gpiozero.DigitalOutputDevice(pin=11, initial_value=False) self.grpC_pin = gpiozero.DigitalOutputDevice(pin=10, initial_value=False) self.grpD_pin = gpiozero.DigitalOutputDevice(pin=9, initial_value=False) print("Initialised Output pins") # These are the input pins. I need to check which circuit is closed. self.outA_pin = gpiozero.DigitalInputDevice(pin=8) self.outB_pin = gpiozero.DigitalInputDevice(pin=7) self.outC_pin = gpiozero.DigitalInputDevice(pin=6) self.outD_pin = gpiozero.DigitalInputDevice(pin=5) self.inpins = [ self.outA_pin, self.outB_pin, self.outC_pin, self.outD_pin ] print("Initialised Input pins") elif dial_mode == 'rotary': print("Using rotary dialling!") trigger_pin = 17 counter_pin = 27 self.trigger_button = gpiozero.Button(trigger_pin, pull_up=False) self.pulse_button = gpiozero.Button(counter_pin, pull_up=False) self.N_PULSES = 0 self._rotary_pressed = None self.pulse_button.when_deactivated = self.add_pulse self.trigger_button.when_activated = self.trigger_activated self.trigger_button.when_deactivated = self.trigger_deactivated # There is no such thing as zero pulses from the rotary dial. self.rotary_buttons = [None, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] self.ping_buttons = self.rotary_ping # This variable holds the name of a button if it's function needs to be called self.call_button = None # Last button that was pushed self.last_button = None # Button press history, since handset was raised self.sequence = [] self._polling = False # True only while the handset is up self._handset_raised = False self.handset_button = gpiozero.Button(handset_pin, pull_up=False) self.handset_button.when_pressed = self.handset_up self.handset_button.when_released = self.handset_down if dummy_mode: self.mock_pins = [] self.mock_pins.append(gpiozero.Device.pin_factory.pin(handset_pin)) for btn_pin in [8, 7, 6, 5]: self.mock_pins.append(gpiozero.Device.pin_factory.pin(btn_pin)) print("Created dummy pin {}".format(btn_pin)) threading.Thread(target=self.poll_buttons, daemon=True).start() print("Button monitor working!")
# Set the image size. vc0706.image_size = adafruit_vc0706.IMAGE_SIZE_640x480 # Note you can also read the property and compare against those values to see the current size: imageSize = vc0706.image_size if imageSize == adafruit_vc0706.IMAGE_SIZE_640x480: print('Using 640x480 size image.') elif imageSize == adafruit_vc0706.IMAGE_SIZE_320x240: print('Using 320x240 size image.') elif imageSize == adafruit_vc0706.IMAGE_SIZE_160x120: print('Using 160x120 size image.') print('Camera has been configured.') ## Ultrasonic sensor setup echoPin = gpiozero.DigitalInputDevice(ULTRA_ECHO_PIN_NUM) trigPin = gpiozero.DigitalOutputDevice(ULTRA_TRIG_PIN_NUM) trigPin.off() print('Ultrasonic sensor has been configured.') ## Humidity sensor setup humidSensor = Adafruit_DHT.DHT22 humidPin = HUMID_PIN_NUM print('Humidity sensor has been configured.') ## SPI setup # Sets up MCP3202 ADCs solarIrradADC = gpiozero.MCP3202(channel=0, differential=True, select_pin=SOLAR_IRRAD_SEL_PIN_NUM) powerOutADC = gpiozero.MCP3202(channel=0, differential=True, select_pin=POWER_OUT_SEL_PIN_NUM) surfTempADC0 = gpiozero.MCP3208(channel=0, differential=False, select_pin=13)
def __init__(self, trigger_pin, echo_pin): self.trigger_pin = gpiozero.OutputDevice(trigger_pin) self.echo_pin = gpiozero.DigitalInputDevice(echo_pin) self.round_distance = 0
def read_pir(): pir = gpiozero.DigitalInputDevice(5) pir.value()