Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

MCP Conveniece methods #18

@andig

Description

@andig

I'd also like to suggest adding the following convenience methods- these allow using the MCP as a byte/word driver in parallel mode and are structured similiar to the Adafruit_I2C class:

def readU8(self):
    result = self.i2c.readU8(MCP23017_OLATA)
    return(result)

def readS8(self):
    result = self.i2c.readU8(MCP23017_OLATA)
    if (result > 127): result -= 256
    return result

def readU16(self):
    assert self.num_gpios >= 16, "16bits required"
    lo = self.i2c.readU8(MCP23017_OLATA)
    hi = self.i2c.readU8(MCP23017_OLATB)
    return((hi << 8) | lo)

def readS16(self):
    assert self.num_gpios >= 16, "16bits required"
    lo = self.i2c.readU8(MCP23017_OLATA)
    hi = self.i2c.readU8(MCP23017_OLATB)
    if (hi > 127): hi -= 256
    return((hi << 8) | lo)

def write8(self, value):
    self.i2c.write8(MCP23017_OLATA, value)

def write16(self, value):
    assert self.num_gpios >= 16, "16bits required"
    self.i2c.write8(MCP23017_OLATA, value & 0xFF)
    self.i2c.write8(MCP23017_OLATB, (value >> 8) & 0xFF)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions