python类setmode()的实例源码

reflectance_sensors.py 文件源码 项目:Bahavior-Based-Robot 作者: Marcgrippa 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setup(self):
        # Initialize class variables
        self.max_val = [-1, -1, -1, -1, -1, -1]
        self.min_val = [-1, -1, -1, -1, -1, -1]
        self.start_time = -1
        # Initialize value array to all negative values, which should never appear
        # as an actual result
        self.value = [-1.0, -1.0, -1.0, -1.0, -1.0, -1.0]
        # A dictionary mapping each channel to the index it's value is located in
        # the value array
        self.sensor_indices = {29: 5, 36: 4, 37: 3, 31: 2, 32: 1, 33: 0}
        self.updated = False
        # For GPIO.BOARD
        self.sensor_inputs = [33, 32, 31, 37, 36, 29]  # Sensors from left to right

        # Set the mode to GPIO.BOARD
        GPIO.setmode(GPIO.BOARD)
L298NHBridge.py 文件源码 项目:raspberry 作者: ykevin 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, left_pin1, left_pin2, right_pin1, right_pin2, leftpwm_pin, rightpwm_pin):
        io.setmode(io.BCM)
        # Constant values
        self.PWM_MAX = 100
        # Here we configure the GPIO settings for the left and right motors spinning direction. 
        # It defines the four GPIO pins used as input on the L298 H-Bridge to set the motor mode (forward, reverse and stopp).
        self.leftmotor_in1_pin = left_pin1
        self.leftmotor_in2_pin = left_pin2
        self.rightmotor_in1_pin = right_pin1
        self.rightmotor_in2_pin = right_pin2
        self.leftmotorpwm_pin = leftpwm_pin
        self.rightmotorpwm_pin = rightpwm_pin
        self.SetupGPIO()
        self.leftmotorpwm = io.PWM(self.leftmotorpwm_pin,100)
        self.rightmotorpwm = io.PWM(self.rightmotorpwm_pin,100)
        self.InitPWM()
        # Disable warning from GPIO
        io.setwarnings(False)
L298NHBridge.py 文件源码 项目:raspberry 作者: ykevin 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, left_pin1, left_pin2, right_pin1, right_pin2, leftpwm_pin, rightpwm_pin):
        io.setmode(io.BCM)
        # Constant values
        self.PWM_MAX = 100
        # Here we configure the GPIO settings for the left and right motors spinning direction. 
        # It defines the four GPIO pins used as input on the L298 H-Bridge to set the motor mode (forward, reverse and stopp).
        self.leftmotor_in1_pin = left_pin1
        self.leftmotor_in2_pin = left_pin2
        self.rightmotor_in1_pin = right_pin1
        self.rightmotor_in2_pin = right_pin2
        self.leftmotorpwm_pin = leftpwm_pin
        self.rightmotorpwm_pin = rightpwm_pin
        self.SetupGPIO()
        self.leftmotorpwm = io.PWM(self.leftmotorpwm_pin,100)
        self.rightmotorpwm = io.PWM(self.rightmotorpwm_pin,100)
        self.InitPWM()
        # Disable warning from GPIO
        io.setwarnings(False)
HX711.py 文件源码 项目:FoodBox_Hardware 作者: FatCatProject 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, dout=4, pd_sck=18, gain=128, readBits=24, offset=-96096, scale=925):
        self.PD_SCK = pd_sck
        self.DOUT = dout
        self.readBits = readBits
        self.twosComplementOffset = 1 << readBits
        self.twosComplementCheck = self.twosComplementOffset >> 1

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.PD_SCK, GPIO.OUT)
        GPIO.setup(self.DOUT, GPIO.IN)

        self.GAIN = 0
        self.set_offset(offset)
        self.set_scale(scale)
        self.lastVal = 0

        self.set_gain(gain)
color.py 文件源码 项目:DSHackathon 作者: DylanWalseth 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self):
        self.led_gpio_red = 17 # red
        self.led_gpio_green = 27 # green
        self.led_gpio_blue = 22 # blue
        self.r = 0.0
        self.g = 0.0
        self.b = 0.0
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.led_gpio_red, GPIO.OUT)
        GPIO.setup(self.led_gpio_green, GPIO.OUT)
        GPIO.setup(self.led_gpio_blue, GPIO.OUT)
        GPIO.output(self.led_gpio_red, True)
        GPIO.output(self.led_gpio_green, True)
        GPIO.output(self.led_gpio_blue, True)
        self.pwm_red = GPIO.PWM(self.led_gpio_red, 100)
        self.pwm_green = GPIO.PWM(self.led_gpio_green, 100)
        self.pwm_blue = GPIO.PWM(self.led_gpio_blue, 100)
        self.pwm_red.start(0)
        self.pwm_green.start(0)
        self.pwm_blue.start(0)
drive.py 文件源码 项目:SDRC 作者: yazeedalrubyli 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setwarnings(False)

        GPIO.setup(self.MotorFront1, GPIO.OUT)
        GPIO.setup(self.MotorFront2, GPIO.OUT)
        GPIO.setup(self.MotorFront, GPIO.OUT)
        GPIO.output(self.MotorFront, 0)

        GPIO.setup(self.MotorBack1, GPIO.OUT)
        GPIO.setup(self.MotorBack2, GPIO.OUT)
        GPIO.setup(self.MotorBack, GPIO.OUT)
        GPIO.output(self.MotorBack, 0)
        self.BackPWM = GPIO.PWM(self.MotorBack,100)
        self.BackPWM.start(0)
        self.BackPWM.ChangeDutyCycle(0)

        self.direction = 0
servo3.py 文件源码 项目:10-4-a-robot 作者: gruener-campus-malchow 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def rotate_motor(duration,sleeptime):
   import RPi.GPIO as GPIO
   #import time

   servoPIN = 17
   GPIO.setmode(GPIO.BCM)
   GPIO.setup(servoPIN, GPIO.OUT)

   p = GPIO.PWM(servoPIN, 500) # GPIO 18 als PWM mit 50Hz
   p.start(2.5) # Initialisierung
   try:

      while duration > 0:
        p.ChangeDutyCycle(1)
    print 'motor running'+str(duration)
        time.sleep(sleeptime)
        duration -= 1
      p.stop()
      GPIO.cleanup()
   except KeyboardInterrupt:
      p.stop()
      GPIO.cleanup()
servo3.py 文件源码 项目:10-4-a-robot 作者: gruener-campus-malchow 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def rotate_motor(duration,sleeptime):
   import RPi.GPIO as GPIO
   #import time

   servoPIN = 17
   GPIO.setmode(GPIO.BCM)
   GPIO.setup(servoPIN, GPIO.OUT)

   p = GPIO.PWM(servoPIN, 500) # GPIO 18 als PWM mit 50Hz
   p.start(2.5) # Initialisierung
   try:

      while duration > 0:
        p.ChangeDutyCycle(1)
    print 'motor running'+str(duration)
        time.sleep(sleeptime)
        duration -= 1
      p.stop()
      GPIO.cleanup()
   except KeyboardInterrupt:
      p.stop()
      GPIO.cleanup()
gpio_watchdog.py 文件源码 项目:Webradio_v2 作者: Acer54 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __initGPIOs(self):
        #setup GPIO using Board numbering (pins, not GPIOs)
        GPIO.setwarnings(False)
        GPIO.cleanup()
        GPIO.setmode(GPIO.BOARD)

        #setup defined pins and event_detectors or outputs and initial states (initial is always 0, low)
        for pin in pins_in_use:
            if pins_in_use[pin][0] == GPIO.IN:
                if pin == 5:
                    GPIO.setup(pin, pins_in_use[pin][0], pull_up_down=GPIO.PUD_UP)
                else:
                    GPIO.setup(pin, pins_in_use[pin][0])
                GPIO.add_event_detect(pin, pins_in_use[pin][1], callback=self.shoutItOut, bouncetime=100)
                self.gpio_states.update({pin: 1})
            elif pins_in_use[pin][0] == GPIO.OUT:
                GPIO.setup(pin, pins_in_use[pin][0], initial=0)
gpio_watchdog.py 文件源码 项目:Webradio_v2 作者: Acer54 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self,pinA,pinB,button,callback, parent):
        self.pinA = pinA
        self.pinB = pinB
        self.button = button
        self.callback = callback
        self.parent = parent
        if self.pinA is not None and self.pinB is not None:
            GPIO.setmode(GPIO.BOARD)

            GPIO.setwarnings(False)
            GPIO.setup(self.pinA, GPIO.IN)
            GPIO.setup(self.pinB, GPIO.IN)
            GPIO.add_event_detect(self.pinA, GPIO.FALLING,
            callback=self.switch_event)
            GPIO.add_event_detect(self.pinB, GPIO.FALLING,
            callback=self.switch_event)

        if self.button is not None:
            GPIO.setup(self.button, GPIO.IN)
            GPIO.add_event_detect(self.button, GPIO.BOTH,
            callback=self.button_event, bouncetime=200)

        return
        # Call back routine called by switch events
Pin.py 文件源码 项目:kiota 作者: Morteo 项目源码 文件源码 阅读 22 收藏 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 项目源码 文件源码 阅读 22 收藏 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 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def setup_GPIO():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(7, GPIO.OUT)
    GPIO.setup(37, GPIO.OUT)
RPiGPIO.py 文件源码 项目:coliform-project 作者: uprm-research-resto 项目源码 文件源码 阅读 30 收藏 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 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setmodeboard(self):
        if self.importlib is not None:
            GPIO.setmode(GPIO.BOARD)
com_gpio.py 文件源码 项目:StratoBalloon 作者: delattreb 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def setmodebcm(self):
        if self.importlib is not None:
            GPIO.setmode(GPIO.BCM)
voctolight.py 文件源码 项目:voctomix-outcasts 作者: CarlFK 项目源码 文件源码 阅读 27 收藏 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 项目源码 文件源码 阅读 20 收藏 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
rpi_wake_button.py 文件源码 项目:susi_linux 作者: fossasia 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self):
        super().__init__()
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GpioPower.py 文件源码 项目:Rpi-envMonitor 作者: conanwhf 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _GPIO_Power_Regist(pins):
    GPIO.setmode(GPIO.BOARD)
    GPIO.setwarnings(False)
    GPIO.setup( pins , GPIO.OUT)
    return


问题


面经


文章

微信
公众号

扫码关注公众号