The micropython sdk contains two main modules - modules.display and modules.input. Import them at the top of your file with:
import modules.display as display
import modules.input as input
Display
General shape
To make changes to the display, call the following functions to update the frame buffer in RAM. Then call display.update() to send the data to the screen.
All colours are in RGB565 format.
display.pixel
Arguments: x, y, colour.
Draws a single pixel to the screen. Unlike the other drawing functions in this legacy implementation, this currently sends the changed buffer to the display immediately.
display.fill
Argument: colour.
Fills the entire frame buffer with one colour. Call display.update() to
send it to the screen.
display.rect
Arguments: x, y (top left corner), width, height, colour.
Draws the outline of a rectangle to the frame buffer.
display.text
Arguments: text, x, y, colour
Draws text to the screen at top left coords of x and y. A single character is size 8x8.
display.draw_image
Arguments: image_name, x, y, image_width, image_height
Draws an image stored in /img in the device’s flash to the screen. The logic cannot infer the image width and height, so you must explicitly pass them.
The earlier version of the web editor placed uploaded images in this directory automatically.
display.update
No arguments.
Flushes data to the display.
Input
The input module deals with button presses.
General shape
Call input.update to check all the buttons, and update state (this includes moving the store of current button presses to last button presses). Call this before you do any input handling in your main game loop
Key names are strings, and are “A”, “B”, “UP”, “DOWN”, “LEFT” and “RIGHT”
input.is_pressed
Argument: key name
Returns a boolean on whether it is currently pressed
input.was_just_pressed
Argument: key name
Returns true if the key is pressed this frame but was not last frame.
input.was_just_released
Argument: key name
Returns true if the key was pressed last frame but was not this frame.