pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

Atomic Base

UIFlow 1.0 Project

Module USB

Example

Initialize the mouse HID HOST, and after connecting the mouse, read the cursor's x, y coordinates and button status.
from m5stack import *
from m5ui import *
from uiflow import *
import module

import time
setScreenColor(0x222222)

usb = module.get(module.USBHOST)

usb.max3421e_init(sclk=18, mosi=23, miso=19, cs=5, irq=35)
usb.hid_init()
while True:
  usb.hid_poll()
  if usb.mouse_button_status(1):
    print('mouse button left click')
  if usb.mouse_button_status(2):
    print('mouse button right click')
  if usb.mouse_button_status(4):
    print('mouse button center click')
  print((str('X:') + str((usb.mouse_cursor_x))))
  print((str('Y:') + str((usb.mouse_cursor_y))))
  wait(1)
  wait_ms(2)

API

import module
usb = module.get(module.USBHOST)
usb.max3421e_init(sclk=18, mosi=23, miso=19, cs=5, irq=35)
  • Initialize the USB Module.
usb.hid_init()
  • Initialize Mouse HID Host
usb.hid_poll()
  • Refresh the status of the input devices.
usb.mouse_button_status(status):
  • Get the button status:
    • status:
      • left:1
      • right:2
      • left+right:3
      • center:4
      • left+center:5
      • right+center:6
      • left+right+center:7
  • Return:
    • True/False
usb.mouse_cursor_x
usb.mouse_cursor_y
  • Get the cursor position of the input device
usb.write_output_pin(PIN,0)
  • Module output IO, control the output voltage level
    • PIN:0-4
usb.read_input_pin(PIN)
  • Module input IO, read the input voltage level
    • PIN:0-4
usb.read_output_pin(PIN)
  • Module output IO, read the output voltage level.
    • PIN:0-4
On This Page