pdf-icon

UIFlow Guide

UiFlow1 Blockly

Event

Unit

UiFlow1 Project

Unit 8Encoder

Example

Edit program, open 1/2/3 rotary encoder, and listen to encoder statistics

from m5stack import *
from m5ui import *
from uiflow import *
import unit

setScreenColor(0x222222)
encoder8_0 = unit.get(unit.ENCODER8, unit.PORTA)

encoder8_0.init_i2c_address(0x41)
encoder8_0.set_LED_RGB24(2, 50, 50, 50)
while True:
  print((str('counter 1 value:') + str((encoder8_0.get_counter_value(1)))))
  print((str('counter 2 value:') + str((encoder8_0.get_counter_value(2)))))
  print((str('counter 3 value:') + str((encoder8_0.get_counter_value(3)))))
  wait_ms(2)

API

encoder8_0.init_i2c_address(0x41)
  • Initialize the Encoder8 unit using the specified I2C interface and address
print((str('button status:') + str((encoder8_0.get_button_status(0)))))
  • Get the button status of the specified channel
print((str('counter value:') + str((encoder8_0.get_counter_value(0)))))
  • Get the counter value of the specified channel
print((str('device status:') + str((encoder8_0.read_status(0xFE)))))
  • Get the device status and version
print((str('increment value:') + str((encoder8_0.get_increment_value(0)))))
  • Get the increment value of the specified channel
print((str('switch status:') + str((encoder8_0.get_switch_status()))))
  • Get the status of the global switch
encoder8_0.reset_counter_value(0)
  • Reset the counter value of the specified channel
encoder8_0.reset_counter_value(0)
  • Set the counter value of the specified channel
encoder8_0.set_i2c_address(0x41)
  • Set a new I2C address for the device
encoder8_0.set_LED_RGB24(0, 50, 50, 50)
  • Set the RGB color of the specified channel
encoder8_0.set_LED_RGB24_From(0, 0, 50, 50, 50)
  • Set the RGB color for a series of channels
On This Page