当前位置: 首页>>代码示例>>Python>>正文


Python pigpio.pi方法代码示例

本文整理汇总了Python中pigpio.pi方法的典型用法代码示例。如果您正苦于以下问题:Python pigpio.pi方法的具体用法?Python pigpio.pi怎么用?Python pigpio.pi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pigpio的用法示例。


在下文中一共展示了pigpio.pi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def __init__(self, bg, pw_up=1700, pw_down=1300, pin=18, transition_time=0.25, virtual_mode=False):

        self.bg = bg
        self.pin = pin
        self.pw_up = pw_up
        self.pw_down = pw_down
        self.transition_time = transition_time
        self.virtual_mode = virtual_mode
        if self.virtual_mode:

            print("Initialising virtual Pen")

        else:

            self.rpi = pigpio.pi()
            self.rpi.set_PWM_frequency(self.pin, 50)

        self.up()
        sleep(0.3)
        self.down()
        sleep(0.3)
        self.up()
        sleep(0.3) 
开发者ID:evildmp,项目名称:BrachioGraph,代码行数:25,代码来源:brachiograph.py

示例2: button_callback

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def button_callback(self, gpio, level, tick):
        """
        This method receives a change in state of the
        pushbutton.

        It will print the current state to the console
        and reflect that state by turning the LED on
        or OFF based on the state.

        It will also publish a message containing the state
        change.

        :param gpio: pin number
        :param level: pin level
        :param tick: timer tick
        """
        print('The pushbutton state is {} on pin {} '
              'and changed at tick {}'.format(level, gpio, tick))

        self.pi.write(self.led, level)

        # create a publishing payload
        payload = {'pushbutton state': level, 'gpio_pin': gpio,
                   'time_tick':tick}
        self.publish_payload(payload, self.publish_topic) 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:27,代码来源:single.py

示例3: __init__

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def __init__(self, pi, trigger, echo):
        """
        The class is instantiated with the Pi to use and the
        gpios connected to the trigger and echo pins.
        """
        self.pi = pi
        self._trig = trigger
        self._echo = echo

        self._ping = False
        self._high = None
        self._time = None

        self._triggered = False

        self._trig_mode = pi.get_mode(self._trig)
        self._echo_mode = pi.get_mode(self._echo)

        pi.set_mode(self._trig, pigpio.OUTPUT)
        pi.set_mode(self._echo, pigpio.INPUT)

        self._cb = pi.callback(self._trig, pigpio.EITHER_EDGE, self._cbf)
        self._cb = pi.callback(self._echo, pigpio.EITHER_EDGE, self._cbf)

        self._inited = True 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:27,代码来源:sonar.py

示例4: read

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def read(self):
        """
        Triggers a reading.  The returned reading is the number
        of microseconds for the sonar round-trip.

        round trip cms = round trip time / 1000000.0 * 34030
        """
        if self._inited:
            self._ping = False
            self.pi.gpio_trigger(self._trig)
            start = time.time()
            while not self._ping:
                if (time.time() - start) > 5.0:
                    return 20000
                time.sleep(0.001)
            return self._time
        else:
            return None 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:20,代码来源:sonar.py

示例5: i2c_write

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def i2c_write(self, topic, payload):
        """
        This method will perform an i2c write for the i2c device with
        the specified i2c device address, i2c register and a list of byte
        to write.

        Call set_mode_i2c first to establish the pins for i2c operation.

        :param topic: message topic
        :param payload: {"command": "i2c_write", "pin": “PIN”, "tag": "TAG",
                         "addr": “I2C ADDRESS, "register": “I2C REGISTER”,
                         "data": [“DATA IN LIST FORM”]}
        """

        if self.i2c_handle is None:
            self.i2c_handle = self.pi.i2c_open(1, payload['addr'], 0)

        data = payload['data']

        self.pi.i2c_write_device(self.i2c_handle, data)

        # give the i2c device some time to process the write request
        time.sleep(.4) 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:25,代码来源:rpi_gateway.py

示例6: set_mode_analog_input

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def set_mode_analog_input(self, topic, payload):
        """
        This method programs a PCF8591 AD/DA for analog input.
        :param topic: message topic
        :param payload: {"command": "set_mode_analog_input",
                         "pin": “PIN”, "tag":”TAG” }
        """

        # pin is used as channel number

        value = None
        i2c_handle = self.pi.i2c_open(1, 72, 0)
        pin = payload['pin']

        self.pi.i2c_write_byte_data(i2c_handle, 64 | (pin & 0x03), 0)
        time.sleep(0.1)
        for i in range(3):
            value = self.pi.i2c_read_byte(i2c_handle)

        self.pi.i2c_close(i2c_handle)

        # publish an analog input report
        payload = {'report': 'analog_input', 'pin': pin,
                   'value': value}
        self.publish_payload(payload, 'from_rpi_gateway') 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:27,代码来源:rpi_gateway.py

示例7: xy_to_angles

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def xy_to_angles(self, x=0, y=0):

        # convert x/y co-ordinates into motor angles

        hypotenuse = math.sqrt(x**2+y**2)

        if hypotenuse > self.INNER_ARM + self.OUTER_ARM:
            raise Exception(f"Cannot reach {hypotenuse}; total arm length is {self.INNER_ARM + self.OUTER_ARM}")

        hypotenuse_angle = math.asin(x/hypotenuse)

        inner_angle = math.acos(
            (hypotenuse**2+self.INNER_ARM**2-self.OUTER_ARM**2)/(2*hypotenuse*self.INNER_ARM)
        )
        outer_angle = math.acos(
            (self.INNER_ARM**2+self.OUTER_ARM**2-hypotenuse**2)/(2*self.INNER_ARM*self.OUTER_ARM)
        )

        shoulder_motor_angle = hypotenuse_angle - inner_angle
        elbow_motor_angle = math.pi - outer_angle

        return (math.degrees(shoulder_motor_angle), math.degrees(elbow_motor_angle)) 
开发者ID:evildmp,项目名称:BrachioGraph,代码行数:24,代码来源:brachiograph.py

示例8: angles_to_xy

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def angles_to_xy(self, shoulder_motor_angle, elbow_motor_angle):

        # convert motor angles into x/y co-ordinates

        elbow_motor_angle = math.radians(elbow_motor_angle)
        shoulder_motor_angle = math.radians(shoulder_motor_angle)

        hypotenuse = math.sqrt(
            (self.INNER_ARM ** 2 + self.OUTER_ARM ** 2 - 2 * self.INNER_ARM * self.OUTER_ARM * math.cos(
                math.pi - elbow_motor_angle)
            )
        )
        base_angle = math.acos(
            (hypotenuse ** 2 + self.INNER_ARM ** 2 - self.OUTER_ARM ** 2) / (2 * hypotenuse * self.INNER_ARM)
        )
        inner_angle = base_angle + shoulder_motor_angle

        x = math.sin(inner_angle) * hypotenuse
        y = math.cos(inner_angle) * hypotenuse

        return(x, y)


    # ----------------- calibration ----------------- 
开发者ID:evildmp,项目名称:BrachioGraph,代码行数:26,代码来源:brachiograph.py

示例9: __init__

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def __init__(self, pin, pud):
        """
        Args:
            pin (int): (Board) pin number
            pud ('U', 'D'): Pull the pin 'U'p or 'D'own.
        """
        self.pig = pigpio.pi()
        if not self.pig.connected:
            Exception('No connection to pigpio daemon could be made')

        self.pin = BOARD_TO_BCM[int(pin)]

        if pud == 1:
            self.pig.set_pull_up_down(self.pin, pigpio.PUD_UP)
        elif pud == 0:
            self.pig.set_pull_up_down(self.pin, pigpio.PUD_DOWN) 
开发者ID:wehr-lab,项目名称:autopilot,代码行数:18,代码来源:hardware.py

示例10: getTFminiData

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def getTFminiData():
	while True:
		#print("#############")
		time.sleep(0.05)	#change the value if needed
		(count, recv) = pi.bb_serial_read(RX)
		if count > 8:
			for i in range(0, count-9):
				if recv[i] == 89 and recv[i+1] == 89: # 0x59 is 89
					checksum = 0
					for j in range(0, 8):
						checksum = checksum + recv[i+j]
					checksum = checksum % 256
					if checksum == recv[i+8]:
						distance = recv[i+2] + recv[i+3] * 256
						strength = recv[i+4] + recv[i+5] * 256
						if distance <= 1200 and strength < 2000:
							print(distance, strength) 
						#else:
							# raise ValueError('distance error: %d' % distance)	
						#i = i + 9 
开发者ID:TFmini,项目名称:TFmini-RaspberryPi,代码行数:22,代码来源:tfmini_ss.py

示例11: Spell

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def Spell(spell):
    #clear all checks
    ig = [[0] for x in range(15)]
    #Invoke IoT (or any other) actions here
    cv2.putText(mask, spell, (5, 25),cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255,0,0))
    if (spell=="Colovaria"):
        print("GPIO trinket")
        pi.write(trinket_pin,0)
        time.sleep(1)
        pi.write(trinket_pin,1)
    elif (spell=="Lumos"):
        print("GPIO ON")
        pi.write(switch_pin,1)
    elif (spell=="Nox"):
        print("GPIO OFF")
        pi.write(switch_pin,0)
    print("CAST: %s" %spell)

#IsGesture is called to determine whether a gesture is found within tracked points 
开发者ID:sean-obrien,项目名称:rpotter,代码行数:21,代码来源:rpotter.py

示例12: _setup_pin

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def _setup_pin(self, pin):
		self._logger.debug(u"_setup_pin(%s)" % (pin,))
		if pin:
			p = None
			startup = 100.0 if self._settings.get_boolean(['on_startup']) else 0.0

			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(startup)
			return p 
开发者ID:google,项目名称:OctoPrint-LEDStripControl,代码行数:24,代码来源:__init__.py

示例13: init_softspi_mcp

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def init_softspi_mcp():
    try:
        retval = pi.bb_spi_open(CS, MISO, MOSI, SCLK, 20000, 0)
    except pigpio.error as e:
        if str(e) == "'GPIO already in use'":
            retval = 0
        else:
            raise 
开发者ID:WLANThermo,项目名称:WLANThermo_v2,代码行数:10,代码来源:wlt_2_comp.py

示例14: get_channel_mcp

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def get_channel_mcp(channel):
    if channel > 7:
        raise ValueError()
    command = pack('>Hx', (0x18 + channel) << 6)
    return unpack('>xH', pi.bb_spi_xfer(CS, command)[1])[0] & 0x0FFF 
开发者ID:WLANThermo,项目名称:WLANThermo_v2,代码行数:7,代码来源:wlt_2_comp.py

示例15: get_channel_max31855

# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pi [as 别名]
def get_channel_max31855(channel):
    if channel > 1:
        raise ValueError()
    data = BitArray(pi.bb_spi_xfer(8 - channel, '\00\00')[1])
    if data[15]:
        return None
    else:
        return data[0:14].int / 4.0 
开发者ID:WLANThermo,项目名称:WLANThermo_v2,代码行数:10,代码来源:wlt_2_comp.py


注:本文中的pigpio.pi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。