def get_pinfactory(hostport=None, timeout=1): """ Get the pinfactory for the configured hostport. :param hostport: the host/port tuple, when None local GPIO is used """ global _LOCAL_FACTORY, _REMOTE_FACTORY # TODO do we need any thread safety here? pin_factory = None if hostport and hostport[0]: from gpiozero.pins.pigpio import PiGPIOFactory pin_factory = get_remote_pinfactory(hostport, timeout) # if we don't have a pin_factory, create a new one if pin_factory is None: _LOGGER.info("Creating pigpiod connection to %s:%s", hostport[0], hostport[1]) try: pin_factory = PiGPIOFactory(host=hostport[0], port=hostport[1]) # We set a timeout so that we can determine if the # connection dies pin_factory._connection.sl.s.settimeout(timeout) _REMOTE_FACTORY[hostport] = pin_factory except IOError as e: _LOGGER.error("error connecting to pigpio due to: %s", e) pin_factory = None else: from gpiozero.pins.rpigpio import RPiGPIOFactory if _LOCAL_FACTORY is None: _LOCAL_FACTORY = RPiGPIOFactory() pin_factory = _LOCAL_FACTORY return pin_factory
def __init__(self): self.led = None self.color = '#FFFFFF' self.is_on = False self.btn = None self.is_btn_en = False self.gcode_command_enable = False self.gcode_index_enable = False self.gcode_rgb_index = 1 self.pin_factory = RPiGPIOFactory()
def __init__(self): self.fan = None self.speed = 0.0 self.gcode_command_enable = False self.gcode_index_enable = False self.gcode_fan_index = 4 self.pin_factory = RPiGPIOFactory() self.cpu_fan_timer = None self.cpu_fan_enable = False self.cpu_fan_temp_min = CPU_FAN_TEMP_MIN_DEFAULT self.cpu_fan_temp_max = CPU_FAN_TEMP_MAX_DEFAULT self.cpu_fan_speed_min = CPU_FAN_SPEED_MIN_DEFAULT self.cpu_fan_speed_max = CPU_FAN_SPEED_MAX_DEFAULT self.cpu_fan_old_temp = None
def main(): """ Main loop """ args = get_args() params = load_params(args) test = False if args.version: print(u'Version : {}'.format(__version__)) sys.exit(0) if args.infos: print_infos(params) sys.exit(0) if args.verbose: print_infos(params) count = 1 if args.test: count = args.test test = True # exit(0) factory = RPiGPIOFactory() fan = PWMLED(params['gpio_pin'], pin_factory=factory) fan.on() fan_on = False fan.value = 0 temp_seuil = (params['temp_max'] + params['temp_min']) / 2 while count > 0: if test: count += -1 temp = get_temp() if not fan_on and temp > temp_seuil: fan_on = True if temp < params['temp_min']: fan_on = False fan.value = 0 if fan_on: voltage = get_voltage(params) fan.value = voltage if test: print(u'temp: {} voltage: {}'.format(temp, fan.value), flush=True) time.sleep(params['sleep_interval'])
DIR_PIN = 21 ENABLE_PIN = 25 MS1_PIN = 24 MS2_PIN = 23 # Default User DEFAULT_USER = "******" # Guard imports behind config flag # This ensures that server can be run in Docker container if app.config["USE_MOTOR"]: import RPi.GPIO as rpigpio from gpiozero.pins.rpigpio import RPiGPIOFactory rpigpio.setmode(rpigpio.BCM) rpigpio.setwarnings(False) Device.pin_factory = RPiGPIOFactory() else: from gpiozero.pins.mock import MockFactory Device.pin_factory = MockFactory() motor_driver = EasyDriver(step_pin=STEP_PIN, dir_pin=DIR_PIN, ms1_pin=MS1_PIN, ms2_pin=MS2_PIN, enable_pin=ENABLE_PIN) ''' Small database model for the users. Used for authentication with JSON web tokens '''
from gpiozero import LED from gpiozero.pins.rpigpio import RPiGPIOFactory from time import sleep local_factory = RPiGPIOFactory() led_1 = LED(17, pin_factory=local_factory) # local pin led_2 = LED(17) # remote pin while True: led_1.on() led_2.off() sleep(1) led_1.off() led_2.on() sleep(1)
# from gpiozero.pins.mock import MockFactory from gpiozero import Device, Button, LED from gpiozero.pins.rpigpio import RPiGPIOFactory factory = RPiGPIOFactory() from LedBlinker import LEDplus import argparse from time import sleep import signal import logging from Game import * game = Game() from Dj import Dj logging.basicConfig(level=logging.DEBUG, format='%(funcName)s:%(lineno)d:%(message)s') Dj("Init") BlueBackPin = 16 # "BOARD36" BlueFrontPin = 13 RedBackPin = 20 #"BOARD38" RedFrontPin = 21 # "BOARD40" #21 AllLedsPin = 4 from MFRCReader import MFRCReader mfrcReader = MFRCReader() # devices buttonBounceTime = None AllButtonsLEDs = LEDplus(AllLedsPin) AllButtonsLEDs._blinkPeriod = 4
import gpiozero as rpi from pymata_aio.pymata3 import PyMata3 from Adafruit_DHT import read_retry as DHT_read_retry from os import _exit from pymata_aio.constants import Constants from . import wfactory from gpiozero.pins.rpigpio import RPiGPIOFactory import sys defaultFactory = RPiGPIOFactory() class DHTsensor: def __init__(self, pin): self.pin = pin def humidityRead(self): return DHT_read_retry(11, self.pin)[0] def temperatureRead(self): return DHT_read_retry(11, self.pin)[1] from serial.serialutil import SerialException print("Starting program...") serialTry = ["/dev/serial0"] ard = None for tries in serialTry: try: ard = PyMata3(com_port=tries) except SerialException:
Wolf Honore Turn the button LEDs on or off. """ import sys from gpiozero import LED # type: ignore from gpiozero.pins.rpigpio import RPiGPIOFactory, RPiGPIOPin # type: ignore # Hack to prevent resetting LED state on exit # See: https://github.com/gpiozero/gpiozero/issues/707 def _close(_self): pass RPiGPIOPin.close = _close PINS = (26, 19, 13, 6) LEDS = [LED(pin, initial_value=None, pin_factory=RPiGPIOFactory()) for pin in PINS] def set_led(idx: int, state: bool) -> None: LEDS[idx].value = state if __name__ == "__main__": states = [bool(int(x)) for x in sys.argv[1:]] for idx, state in enumerate(states): set_led(idx, state)