python类OUT的实例源码

gpio2pd.py 文件源码 项目:pipypd 作者: stressfm 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def RCtime (PiPin):
    measurement = 0
    # Discharge capacitor
    GPIO.setup(PiPin, GPIO.OUT)
    GPIO.output(PiPin, GPIO.LOW)
    time.sleep(0.1)

    GPIO.setup(PiPin, GPIO.IN)
    # Count loops until voltage across
    # capacitor reads high on GPIO
    start = time.time()
    while (GPIO.input(PiPin) == GPIO.LOW):
        measurement += 1

    end = time.time()
    # print end - start
    # return measurement
    return str(end - start)

# Main program loop
RFExplorer.py 文件源码 项目:RFExplorer-for-Python 作者: RFExplorer 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def ResetIOT_HW(cls, bMode):
        """Set Raspberry pi GPIO pins and reset RF Explorer device

        Parameters: 
            bMode -- True if the baudrate is set to 500000bps, False to 2400bps
        """
        try:
            import RPi.GPIO as GPIO

            #print("RPi info: " + str(GPIO.RPI_INFO)) #information about your RPi:
            #print("RPi.GPio version: " + GPIO.VERSION) #version of RPi.GPIO:
            GPIO.setwarnings(False)
            GPIO.setmode(GPIO.BOARD)    #refer to the pin numbers on the P1 header of the Raspberry Pi board
            GPIO.setup(12, GPIO.OUT)    #set /reset (pin 12) to output 
            GPIO.output(12, False)      #set /reset (pin 12) to LOW
            GPIO.setup(21, GPIO.OUT)    #set GPIO2 (pin 21) to output
            GPIO.output(21, bMode)      #set GPIO2 (pin 21) to HIGH (for 500Kbps)
            time.sleep(0.1)             #wait 100ms
            GPIO.output(12, True)       #set /reset to HIGH
            time.sleep(2.5)             #wait 2.5sec
            GPIO.setup(21, GPIO.IN)     #set GPIO2 to input
            GPIO.cleanup()              #clean up GPIO channels 

        except RuntimeError:
            print("Error importing RPi.GPIO!  This is probably because you need superuser privileges.  You can achieve this by using 'sudo' to run your script")
light_sensor.py 文件源码 项目:infilcheck 作者: jonnykry 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def light_sense():

    count = 0

    #Output on the pin for 
    GPIO.setup(pin_to_circuit, GPIO.OUT)
    GPIO.output(pin_to_circuit, GPIO.LOW)
    time.sleep(0.1)

    #Change the pin back to input
    GPIO.setup(pin_to_circuit, GPIO.IN)

    #Count until the pin goes high
    while (GPIO.input(pin_to_circuit) == GPIO.LOW):
        count += 1

    if (count > 3000):
        led5_on()
        return count
    else:
        led5_off()
        return count
__init__.py 文件源码 项目:OctoPrint-LEDStripControl 作者: google 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _setup_pin(self, pin):
        self._logger.debug(u"_setup_pin(%s)" % (pin,))
        if pin:
            p = None

            if self._pigpiod is None:
                self._pigpiod = pigpio.pi()

            if self._settings.get_boolean(['pigpiod']):
                if not self._pigpiod.connected:
                    self._logger.error(u"Unable to communicate with PiGPIOd")
                else:
                    p = PiGPIOpin(self._pigpiod, pin, self._logger)
            else:
                GPIO.setwarnings(False)
                GPIO.setmode(GPIO.BOARD)
                GPIO.setup(pin, GPIO.OUT)
                GPIO.output(pin, GPIO.HIGH)
                p = GPIO.PWM(pin, 100)
            p.start(100)
            return p
TB6612.py 文件源码 项目:SunFounder_PiCar 作者: sunfounder 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, direction_channel, pwm=None, offset=True):
        '''Init a motor on giving dir. channel and PWM channel.'''
        if self._DEBUG:
            print self._DEBUG_INFO, "Debug on"
        self.direction_channel = direction_channel
        self._pwm = pwm
        self._offset = offset
        self.forward_offset = self._offset

        self.backward_offset = not self.forward_offset
        self._speed = 0

        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)

        if self._DEBUG:
            print self._DEBUG_INFO, 'setup motor direction channel at', direction_channel
            print self._DEBUG_INFO, 'setup motor pwm channel as', self._pwm.__name__
        GPIO.setup(self.direction_channel, GPIO.OUT)
buzzer.py 文件源码 项目:rainbow-hat 作者: pimoroni 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def note(frequency, duration=1.0):
    """Play a single note.

    :param frequency: Musical frequency in hertz
    :param duration: Optional duration in seconds, use None to sustain note

    """

    global _timeout

    if frequency <= 0:
        raise ValueError("Frequency must be > 0")

    if duration is not None and duration <= 0:
        raise ValueError("Duration must be > 0")

    clear_timeout()

    pwm.ChangeFrequency(frequency)
    GPIO.setup(BUZZER, GPIO.OUT)    

    if duration is not None and duration > 0:
        _timeout = Timer(duration, stop)
        _timeout.start()
Pin.py 文件源码 项目:kiota 作者: Morteo 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, no, dir=IN):
        self.gpio_no = no
        print("GPIO ########## self.gpio_no, dir={}, {}".format(self.gpio_no, dir))
        GPIO.setmode(GPIO.BCM)
        #GPIO.setmode(GPIO.BOARD)

        if dir==Pin.IN:
          GPIO.setup(self.gpio_no, GPIO.IN)
          print("GPIO >>>>>>>>>>>>>>>>>>>>>>>>>>> IN")
        else:
          GPIO.setup(self.gpio_no, GPIO.OUT)
          print("GPIO <<<<<<<<<<<<<<<<<<<<<<<<<< OUT")
main.py 文件源码 项目:rpi-can-logger 作者: JonnoFTW 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def setup_GPIO():
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(7, GPIO.OUT)
    GPIO.setup(37, GPIO.OUT)
    GPIO.setup(35, GPIO.IN)
gpio_led_test.py 文件源码 项目:rpi-can-logger 作者: JonnoFTW 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def setup_GPIO():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(7, GPIO.OUT)
    GPIO.setup(37, GPIO.OUT)
controller.py 文件源码 项目:cooktop-IoT 作者: gabimachado 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def switchOnLight(PIN):
    GPIO.setup(PIN, GPIO.OUT)
    GPIO.output(PIN, True)
controller.py 文件源码 项目:cooktop-IoT 作者: gabimachado 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def switchOffLight(PIN):
    GPIO.setup(PIN, GPIO.OUT)
    GPIO.output(PIN, False)
RPiGPIO.py 文件源码 项目:coliform-project 作者: uprm-research-resto 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def startup(self):  # funciton that starts th GPIO board and pin required
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self.channel, GPIO.OUT)
        self.pwm = GPIO.PWM(self.channel, self.frequency)
        self.pwm.start(self.frequency)
com_gpio.py 文件源码 项目:StratoBalloon 作者: delattreb 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, name = ''):
        self.importlib = GPIO
        self.logger = com_logger.Logger(name)
        # self.setwarnings(False)
        self.IN = GPIO.IN if GPIO is not None else None
        self.OUT = GPIO.OUT if GPIO is not None else None
        self.LOW = GPIO.LOW if GPIO is not None else None
        self.HIGH = GPIO.HIGH if GPIO is not None else None
        self.PUD_UP = GPIO.PUD_UP if GPIO is not None else None
        self.PUD_DOWN = GPIO.PUD_DOWN if GPIO is not None else None
        self.RISING = GPIO.RISING if GPIO is not None else None
voctolight.py 文件源码 项目:voctomix-outcasts 作者: CarlFK 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def reset_led(self):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setwarnings(False)
        for gpio in self.gpios:
            gpio = int(gpio)
            GPIO.setup(gpio, GPIO.OUT)
            GPIO.output(gpio, GPIO.HIGH)
findDistance.py 文件源码 项目:RaspberryPi-Robot 作者: timestocome 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self):

        gpio.setmode(gpio.BOARD)

        # set up  and init 
        self.trigger = 11
        self.echo = 13

        gpio.setup(self.trigger, gpio.OUT)
        gpio.setup(self.echo, gpio.IN)

        self.pulse_start = 0.
        self.pulse_end = 0.
        self.speed_of_sound = 343 * 100
        self.car_length = 1
GpioPower.py 文件源码 项目:Rpi-envMonitor 作者: conanwhf 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _GPIO_Power_Regist(pins):
    GPIO.setmode(GPIO.BOARD)
    GPIO.setwarnings(False)
    GPIO.setup( pins , GPIO.OUT)
    return
DHT11.py 文件源码 项目:Rpi-envMonitor 作者: conanwhf 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _read_data(self):
        self.data=[]
        # reset        
        GPIO.setup( self.pin , GPIO.OUT)
        GPIO.output( self.pin , GPIO.LOW)
        time.sleep(0.03) # ????18ms
        GPIO.setup( self.pin , GPIO.IN)
        count=0
        while GPIO.input( self.pin ) == GPIO.HIGH:
            continue
        while GPIO.input( self.pin ) == GPIO.LOW:
            continue
        # ????80us???????
        while GPIO.input( self.pin ) == GPIO.HIGH:
            count += 1
            continue
        base = count / 2
        # Get data
        while len(self.data)< DHT11_DATA_LEN*8:
            i = 0
            # ??50us?????
            while GPIO.input( self.pin ) == GPIO.LOW:
                continue
            # ?????????26-28us??0?????70us??1
            while GPIO.input( self.pin ) == GPIO.HIGH:
                i += 1
                if i > 100: #?????
                    break
            if i < base:
                self.data.append(0)
            else:
                self.data.append(1)
        #print("DHT11 get data: ", self.data)
initBot.py 文件源码 项目:Motion-Sensor 作者: Paco1994 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def detect(run_event):
    isDetected = False
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(11, GPIO.IN) # Set GPIO 11 pin as input
    GPIO.setup(12,GPIO.OUT)
    GPIO.setup(16,GPIO.OUT)


    while run_event.is_set():
        i=GPIO.input(11)
        if i==0:         # if don't detect signal
            #print "\033[95mNobody detected.\033[0m",i
            GPIO.output(12,GPIO.HIGH)
            GPIO.output(16,GPIO.LOW)
            isDetected = False
            time.sleep(0.1)
        if i==1 and isDetected == False:       # if detect signal
            GPIO.output(16,GPIO.HIGH)
            GPIO.output(12,GPIO.LOW)
            print "\033[92mSomeone detected.\033[0m --> " + time.strftime("%H:%M:%S")
            bot.send_message(admin, "Someone detected -->   " + time.strftime("%H:%M:%S"))
            for i in range(1, 6, 4):
                print i
                name=video(3*i, frameRate) #One video of 3 seconds and another of 15
                if (name == "error"):
                    bot.send_message (admin, "The camera is busy now.")
                else:
                    bot.send_document(admin, open(name, 'rb'))
            #bot.send_document(admin, open('media/video/' + video(3), 'rb'))
            #bot.send_document(admin, open('media/video/' + video(15), 'rb'))
            print "ya"

            isDetected = True
    GPIO.cleanup()
hydroponics.py 文件源码 项目:hydroponics 作者: tpudlik 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, **kwargs):
        self.pump_pin = kwargs["pump_pin"]
        self.lights_pin = kwargs["lights_pin"]
        self.pump_default_on = kwargs["pump_default_on"]
        self.lights_default_on = kwargs["lights_default_on"]

        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self.pump_pin, GPIO.OUT)
        GPIO.setup(self.lights_pin, GPIO.OUT)
hydroponics.py 文件源码 项目:hydroponics 作者: tpudlik 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, **kwargs):
        self.pump_pin = kwargs["pump_pin"]
        self.lights_pin = kwargs["lights_pin"]
        self.pump_default_on = kwargs["pump_default_on"]
        self.lights_default_on = kwargs["lights_default_on"]

        print "GPIO.setmode(GPIO.BOARD)"
        print "GPIO.setup({}, GPIO.OUT)".format(self.pump_pin)
        print "GPIO.setup({}, GPIO.OUT)".format(self.lights_pin)


问题


面经


文章

微信
公众号

扫码关注公众号