コード例 #1
0
# Change mode to relative (default is absolute)
# You can use setAbsolute() to change back to absolute
# Absolute: the position starts at zero and is incremented or
#           decremented by the encoder's movement
# Relative: the position is reset when the unit timer overflows.
myEncoder.setAbsolute()

# Read the current mode (0: absolute, 1: relative)
# Mode can also be set as a property
mode = myEncoder.mode

# Get the current frequency of update in Hz
freq = myEncoder.frequency

# Set the update frequency to 1 kHz
myEncoder.frequency = 1000

# Check if the channel is enabled
# The 'enabled' property is read-only
# Use the enable() and disable() methods to
# safely enable or disable the module
isEnabled = myEncoder.enabled
myEncoder.enable()

while True:
    print(str(myEncoder.position))
    time.sleep(0.3)
# Disable the eQEP channel
myEncoder.disable()
コード例 #2
0
bus = smbus.SMBus(2)  # select i2c bus 2
matrix = 0x70  # define matrix address on i2c bus

# --------------------MATRIX SETUP--------------------
bus.write_byte_data(matrix, 0x21, 0)  # Start oscillator (p10)
bus.write_byte_data(matrix, 0x81, 0)  # Disp on, blink off (p11)
bus.write_byte_data(matrix, 0xe7, 0)  # Full brightness (page 15)

SW = ["P8_11", "P8_12", "P8_33",
      "P8_35"]  # define switches by their header pin

# set up left/right rotary encoder & refresh at 1000kHz
lrEncoder = RotaryEncoder(eQEP2)
lrEncoder.zero()
lrEncoder.setAbsolute()
lrEncoder.frequency = 1000
lrEncoder.enable()
# set up up/down rotary encoder
udEncoder = RotaryEncoder(eQEP1)
udEncoder.zero()
udEncoder.setAbsolute()
udEncoder.frequency = 1000
udEncoder.enable()


def main():
    print("Welcome to etch a sketch!")
    print("")
    print("8x8 LED edition")

    xdim = 8