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


Python PyMata.i2c_write方法代码示例

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


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

示例1: pair

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import i2c_write [as 别名]
class BiColorDisplayController:
    # display blink control values

    board_address = 0 # i2c address
    blink_rate = 0  # blink rate
    brightness = 0 # brightness

    # blink rate defines
    HT16K33_BLINK_CMD = 0x80
    HT16K33_BLINK_DISPLAYON = 0x01
    HT16K33_BLINK_OFF = 0
    HT16K33_BLINK_2HZ = 1
    HT16K33_BLINK_1HZ = 2
    HT16K33_BLINK_HALFHZ = 3

    # oscillator control values
    OSCILLATOR_ON = 0x21
    OSCILLATOR_OFF = 0x20

    # led color selectors
    LED_OFF = 0
    LED_RED = 1
    LED_YELLOW = 2
    LED_GREEN = 3

    # brightness
    MAX_BRIGHTNESS = 15

    # the display buffer
    # This is an 16x16 matrix that stores pixel data for the display
    # Even rows store the green pixel data and odd rows store the red pixel data.
    #
    # A physical row on the device is controlled by a row pair (ie 0,1 and 2,3, etc) for the 2 colors.
    #
    # To output yellow the red and green information for the rows will be set high.
    #
    display_buffer = [[0 for x in xrange(8)] for x in xrange(8)]


    def __init__(self, address, blink_rate, brightness):

        # create an instance of PyMata - we are using an Arduino UNO
        """

        @param address: I2C address of the device
        @param blink_rate: desired blink rate
        @param brightness: brightness level for the display
        """
        self.firmata = PyMata("/dev/ttyACM0")

        self.board_address = address
        self.blink_rate = blink_rate
        self.brightness = brightness
        self.clear_display_buffer()

        # configure firmata for i2c on an UNO
        self.firmata.i2c_config(0, self.firmata.ANALOG, 4, 5)

        # turn on oscillator
        self.oscillator_set(self.OSCILLATOR_ON)

        # set blink rate
        self.set_blink_rate(self.blink_rate)

        # set brightness
        self.set_brightness(self.brightness)

    def set_blink_rate(self, b):
        """
        Set the user's desired blink rate (0 - 3)
        @param b: blink rate
        """
        if (b > 3):
            b = 0 # turn off if not sure
        self.firmata.i2c_write(self.board_address,
                                 (self.HT16K33_BLINK_CMD | self.HT16K33_BLINK_DISPLAYON | (b << 1)))

    def oscillator_set(self, osc_mode):
        """
        Turn oscillator on or off
        @param osc_mode: osc mode (OSCILLATOR_ON or OSCILLATOR_OFF)
        """
        self.firmata.i2c_write(self.board_address, osc_mode)

    def set_brightness(self, brightness):
        """
        Set the brightness level for the entire display
        @param brightness: brightness level (0 -15)
        """
        if brightness > 15:
            brightness = 15
        brightness |= 0xE0
        self.brightness = brightness
        self.firmata.i2c_write(0x70,  brightness)

    def set_pixel(self, row, column, color, suppress_write):
        # rows 0,2,4,6,8,10,12,14 are green
        # rows 1,3,5,7,9,11,13,15 are red
        #
        # A row entry consists of 2 bytes, the first always being 0 and the second
#.........这里部分代码省略.........
开发者ID:Haobot,项目名称:PyMata,代码行数:103,代码来源:bicolor_display_controller.py

示例2: signal_handler

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import i2c_write [as 别名]
# for uno
# board.i2c_config(0, board.ANALOG, 4, 5)

def signal_handler(sig, frame):
    print('You pressed Ctrl+C!!!!')
    if board is not None:
        board.reset()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)


def lux_callback(data):
    datax = data[2]
    print('Got read data: %s' % data)
    lux = (datax[1] << 8 | datax[2]) >> 4
    lux /= 1.2
    print(str(lux) + ' lux')


while True:
    try:
        board.i2c_write(0x23, board.I2C_READ_CONTINUOUSLY)  # same results with board.I2C_READ
        time.sleep(.3)
        board.i2c_read(0x23, 0, 2, board.I2C_READ, lux_callback)  # same results with board.I2C_READ_CONTINUOUSLY
        time.sleep(.3)
    except KeyboardInterrupt:
        board.close()
开发者ID:MrYsLab,项目名称:PyMata,代码行数:31,代码来源:bh1750_callback.py


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