MICILE EZ_Hardware Documentation
version: 0.9
A few notes about our documentation:
  • The intentions of this documentation are to keep things simple.
  • Please see the examples at the end of each section for concrete examples of how to use each function.
  • If in doubt how to use a function, experiment!
  • We don't believe in writing more words just to make the documentation look more substantial
  • Quick Reference
    Function List
    Compatible Devices
    Accelerometer, Backlight, and Tactile Buttons built into every tablet

    * Please contact us for information on adding support for a device.


    Accelerometer Functions
    read_accelerometer()
    Reads and returns the value of the accelerometer. The values are returned as a list of 3 items. The first item is the acceleration in the X axis, second item is the acceleration in the Y axis, and the third item is the acceleration in the Z axis. Not all hardware supports all three axises, most only support X and Y. In such a case, Z will be returned as zero.
    # --------------------------------------------------
    # accelerometer_demo.py
    # --------------------------------------------------
     
    # import the ez_hardware library v0.9
    # import the ez_graphics library v0.9
    from ez_hardware_09 import *
    from ez_graphics_09 import *
    import time
     
    # init
    x = 0
    y = 0
     
     
    # main loop
    while True:
        # read the accelerometer
        xyz = read_accelerometer()
        
        # format the values in a nice string
        s = "X:%4d Y:%4d Z:%4d" % (xyz[0]xyz[1]xyz[2])
        
        # update the rectangle position
        x = (x + xyz[0]) % 780  # modulus by 780
        y = (y + xyz[1]) % 460  # modules by 460
        
        # clear the screen
        clear_screen('black')
         
        # draw the text and rectangle
        set_text_size(20)
        set_color('yellow')
        draw_text(s50100)
        fill_rect(xy2020)
        
        # flip the drawing page
        flip_page()
        time.sleep(0.001)

    Screen Shot
    Button Functions
    read_buttons()
    Reads and returns the state of hardware buttons. The values are returned as a list of 256 items, with specific buttons having specific indexes into the list. Different buttons have different behaviors. Some only send a response when released, while others will send a response when they are held down. See the chart below for supported buttons and their behaviors.
    ButtonIndexBehavior
    BTN_HOME 102Normally 0, 1 when button is held down. Button must be held down a minimum of half a second for it to respond.
    BTN_POWER 116Normally 0, sends a 1 after the button has been held down and then released
    BTN_VOLUMEDOWN 114Normally 0, 1 when button is held down. Button must be held down a minimum of half a second for it to respond.
    BTN_VOLUMEUP 115Normally 0, 1 when button is held down. Button must be held down a minimum of half a second for it to respond.
    Important notes about the button demo!
  • The BTN_VOLUMEUP and BTN_VOLUMEDOWN take time to charge. Hold them down for more than half a second to see their state change
  • The BTN_POWER only reacts after it has been held down for 0.5 seconds and RELEASED! It will not react when held down, only released.
  • Don't hold down the power button for more than 5 seconds or you will turn off your tablet!
  • # --------------------------------------------------
    # button_demo.py
    # --------------------------------------------------
     
    # import the ez_hardware library v0.9
    # import the ez_graphics library v0.9
    from ez_hardware_09 import *
    from ez_graphics_09 import *
    import time
     
    # clear the screen
    clear_screen('black')
    flip_page()
    clear_screen('black')
    set_text_size(20)
     
    # main loop
    while True:
        # read the accelerometer
        buttons = read_buttons()
        
        # draw a black rectangle behind the text
        set_color('black')
        fill_rect(5075400100)
        
        # change the color of the text depending on the button state
        set_color('gray')
        if BTN_POWER in buttonsset_color('red')
        draw_text('POWER'50100)
        
        set_color('gray')
        if BTN_VOLUMEDOWN in buttonsset_color('red')
        draw_text('VOLUMEDOWN'50125)
     
        set_color('gray')
        if BTN_VOLUMEUP in buttonsset_color('red')
        draw_text('VOLUMEUP'50150)
     
        # change the color of the text depending on the button state
        set_color('gray')
        if BTN_HOME in buttonsset_color('red')
        draw_text('HOME'50175)
     
        # flip the drawing page
        flip_page()
        
        # sleep so app will stop when interrupted
        time.sleep(0.01)

    Screen Shot
    LCD Backlight Functions
    set_brightness(brightness)
    Sets the brightness of the display. Generally the display is black when brightness has a value of less than 80 and the display is at maximum brightness when brightness is set to 255. Allowable values for brightness are 0 to 255.
    # --------------------------------------------------
    # backlight_demo.py
    # --------------------------------------------------
     
    # import the ez_hardware library v0.9
    # import the ez_graphics library v0.9
    from ez_hardware_09 import *
    from ez_graphics_09 import *
     
    # import time
    import time
     
    # clear the screen
    clear_screen('black')
    sw = get_screen_width()
    sh = get_screen_height()
    fill_rect(100100sw - 200sh - 200)
     
    # change the brightness over the range
    for i in range(720):
        set_brightness(i * 10)  # range of 70 to 200
        time.sleep(0.25)        # delay for 0.25 seconds

    Screen Shot

    Battery Functions
    read_battery_status()
    Reads the current status of the battery and returns the status in a dictionary. The dictionary contains the keys shown in the tablet below.

    KeyValue
    battery_percentThe percentage of charge left in the battery.
    Will be an integer number between 0 and 100.
    0 represents empty and 100 represents full.
    battery_statusThe current status of the battery.
    The value returned will be either "Full", "Charging", or "Discharging"
    # --------------------------------------------------
    # battery_demo.py
    # --------------------------------------------------
     
    # import the ez_hardware library v0.9
    # import the ez_graphics library v0.9
    from ez_hardware_09 import *
    from ez_graphics_09 import *
    import time
     
    # initialize
    set_text_size(40)
     
    # main loop
    while True:
        # read the battery
        battery = read_battery_status()
        
        # clear the screen
        clear_screen('black')
        
        # draw the battery percent 
        battery_percent = battery['battery_percent']
        draw_text("Battery Percent: %d%%" % battery_percent50100'green')
        
        # draw the battery status
        battery_status = battery['battery_status']
        draw_text("Battery Status: %s" % battery_status50150'green')
     
        # flip the drawing page
        flip_page()
        
        # sleep so app will stop when interrupted
        time.sleep(0.01)    

    Screen Shot