- API reference expects thumby imported as
import thumby
-
thumby.DISPLAY_W| number of pixels that define the screen width- type: int
- value: 72
thumby.DISPLAY_H| number of pixels that define the screen height- type: int
- value: 40
-
thumby.display.update()| draws result of the below drawing functions to the screen. Call this as little often as possible and after any drawing functions (e.g.thumby.display.rect(...),thumby.display.drawText(...), etc.). Returns Nonethumby.display.fill(color)| fills entire screen withcolor. Returns Nonecolor- type: int
- values: 0 or 1 (default: 0)
thumby.display.setPixel(x, y, color)| sets pixel tocoloratxandy. Returns Nonex- type: int
- values: 0 (left) ~ 71 (right)
y- type: int
- values: 0 (top) ~ 39 (bottom)
color- type: int
- values: 0 or 1 (default: 1)
thumby.display.drawLine(x1, y1, x2, y2, color)| draws 1px thick line incolorfromx1andy1tox2andy2(thickness not variable). Returns Nonex1- type: int
- values: 0 (left) ~ 71 (right)
y1- type: int
- values: 0 (top) ~ 39 (bottom)
x2- type: int
- values: 0 (left) ~ 71 (right)
y2- type: int
- values: 0 (top) ~ 39 (bottom)
color- type: int
- values: 0 or 1 (default: 1)
thumby.display.fillRect(x, y, w, h, color)| creates filled rectangle withcoloratxandywith dimensionsw(width) andh(height). Returns Nonex- type: int
- values: 0 (left) ~ 71 (right)
y- type: int
- values: 0 (top) ~ 39 (bottom)
w- type: int
- values: 0 ~ 71
h- type: int
- values: 0 ~ 39
color- type: int
- values: 0 or 1 (default: 1)
thumby.display.rect(x, y, w, h, color)| creates 1px thick outline rectangle withcoloratxandywith dimensionsw(width) andh(height) (thickness not variable). Returns Nonex- type: int
- values: 0 (left) ~ 71 (right)
y- type: int
- values: 0 (top) ~ 39 (bottom)
w- type: int
- values: 0 ~ 71
h- type: int
- values: 0 ~ 39
color- type: int
- values: 0 or 1 (default: 1)
thumby.display.drawText(string, x, y, color)| drawsstringincoloratxandyin MicroPython's default 8px x 8px font. Returns Nonestring- type: str
- values: 128 ASCII characters
x- type: int
- values: 0 (left) ~ 71 (right)
y- type: int
- values: 0 (top) ~ 39 (bottom)
color- type: int
- values: 0 or 1 (default: 1)
thumby.display.blit(inspr, x, y, width, height, key)| draws pixels defined in bitmapinsprarray atxandyprovided the bitmap'swidthandheightwith transparent pixels defined bykey(e.g.key = 0means black pixels are not drawn/are transparent). Returns Nonex- type: int
- values: 0 (left) ~ 71 (right)
y- type: int
- values: 0 (top) ~ 39 (bottom)
width- type: int
- values: 0 ~ 71
height- type: int
- values: 0 ~ 39
key- type: int
- values: 0 or 1 (default: -1, both black and white pixels drawn)
thumby.display.drawSprite(inspr, x, y, width, height, mirrorX, mirrorY, key)| draws pixels defined in bitmapinsprarray atxandyprovided the bitmap'swidthandheightbut with bitmap mirrorable about x and y axes usingmirrorXandmirrorYflags with transparent pixels defined bykey(e.g.key = 0means black pixels are not drawn/are transparent). Returns Nonex- type: int
- values: 0 (left) ~ 71 (right)
y- type: int
- values: 0 (top) ~ 39 (bottom)
width- type: int
- values: 0 ~ 71
height- type: int
- values: 0 ~ 39
mirrorX- type: bool
- values: 1/True (do mirror) or 0/False (do not mirror)
mirrorY- type: bool
- values: 1/True (do mirror) or 0/False (do not mirror)
key- type: int
- values: 0 or 1 (default: -1, both black and white pixels drawn)
-
thumby.buttonA| for accessing A button (right red button)thumby.buttonB| for accessing B button (left red button)thumby.buttonU| for accessing up direction on DPADthumby.buttonD| for accessing down direction on DPADthumby.buttonL| for accessing left direction on DPADthumby.buttonR| for accessing right direction on DPAD
-
thumby.buttonX.pressed()| returns True ifthumby.buttonXis currently pressed, False otherwise (replacebuttonXby any of the above button objects)thumby.buttonX.justPressed()| returns True if the last button pressed wasthumby.buttonX, False otherwise (replacebuttonXby any of the above button objects)
- Note: audio not implemented on web IDE emulator but is unlikely to cause exceptions
-
thumby.audio.play(freq, duration, duty)| plays audio at sound frequencyfreqand duty cycledutyfordurationin milliseconds without blocking code execution. For now, try searching 'music notes to frequency chart' to relate these parameters to musical notes. Returns Nonefreq- type: int
- values: 7 ~ 125000000 (Hz)
duration- type: int
- values: 0 ~ 2147483647 (ms)
duty- type: uint_16
- values: 0 (0%) ~ 65535 (100%) (default: 32768 or 50%)
thumby.audio.playBlocking(freq, duration, duty)| plays audio at sound frequencyfreqand duty cycledutyfordurationin milliseconds while blocking code execution. For now, try searching 'music notes to frequency chart' to relate these parameters to musical notes. Returns Nonefreq- type: int
- values: 7 ~ 125000000 (Hz)
duration- type: int
- values: 0 ~ 2147483647 (ms)
duty- type: uint_16
- values: 0 (0%) ~ 65535 (100%) (default: 32768 or 50%)
thumby.audio.stop()| stops playing any running audio started bythumby.audio.play(...). Returns Nonethumby.audio.set_enabled(setting)| stops buzzer from outputting sound whenthumby.audio.play()orthumby.audio.playBlocking()are called usingsettingflag.thumby.audio.playBlocking(...)will still block subsequent code execution for the duration provided to it. Returns Nonesetting- type: bool
- values: 1/True (audio enabled) or 0/False (audio disabled)
- Caution: file creation and writing does not work on the web IDE emulator and may cause exceptions
-
thumby.files.openFile(filename, options)| Opens a file provided a file path infilename(e.g. /Games/MyGame/config.txt) with provided Python file openingoptions(https://docs.micropython.org/en/latest/esp8266/tutorial/filesystem.html). Returns Nonefilename- type: str
- values: ASCII path with directories separated by '/'
options- type: str
- values: 'w', 'r', 'wb', 'rb'
thumby.files.closeFile()| closes last file opened withthumby.files.openFile(...). Returns Nonethumby.files.setFile(f)| sets internally tracked file to Python file objectfobtained from outsidethumby.files(e.g.f = open(..., ...)). Returns Nonethumby.files.readFile(l)| readlnumber of bytes from file opened withthumby.files.openFile(...). Returns file contents or "" if no file has been openedl- type: int
- values: 0 ~ 2147483647 (default: -1, read whole file)
thumby.files.writeFile(data)| writesdatato file opened withthumby.files.openFile(...). Returns True if successful, False if not, and -1 if no file has been openeddata- type: str, bytes(...), bytearray(...), etc.
- values: string or binary data depending on what options the file was opened with
thumby.files.changeDirectory(path)| change directory topath(e.g. currently in '/Games' passpathas '/Games/MyGame' now can dof = open("MyGameConfig.txt")). Returns Nonethumby.files.getDirectory()| returns the path to the current directory as a strthumby.files.makeDirectory(path)| makes a directory atpath. Returns Nonepath- type: str
- values: ASCII path with directories separated by '/'