-
Notifications
You must be signed in to change notification settings - Fork 14
Home
This program includes 3 libraries that can help you quickly get a new app up and running.
This library makes it easy to get button inputs from the keyboard matrix on the Cardputer. To use it, you import it with:
from lib import keyboard
Then, you can access the pressed keys like this:
kb = keyboard.KeyBoard() # init the object controlling our keyboard
pressed_keys = kb.get_pressed_keys() # return the currently pressed keys in a list
And that's it! It even automatically applies the 'shift' and 'fn' keys for you, so it's very quick and easy to work with.
Take a look at the keymaps at the top of lib/keyboard.py if you want to see all the possible key values.
This display driver comes from here. This repository has examples and utilities for converting images and fonts into python files, which can be read by the driver.
In the context of MicroHydra on the Cardputer, you can use the driver like this:
from lib import st7789py as st7789
from machine import Pin, SPI
#define static vars for our display settings
display_width = const(240)
display_height = const(135)
#init driver for the graphics
spi = SPI(1, baudrate=40000000, sck=Pin(36), mosi=Pin(35), miso=None)
tft = st7789.ST7789(
spi,
display_height,
display_width,
reset=Pin(33, Pin.OUT),
cs=Pin(37, Pin.OUT),
dc=Pin(34, Pin.OUT),
backlight=Pin(38, Pin.OUT),
rotation=1,
color_order=st7789.BGR
)
#init display by blacking out the screen
tft.fill(st7789.color565(0,0,0))
And there are a bunch more methods in the ST7789 class that you can use for drawing text, images polygons, and for scrolling the display.
Check out the st7789py.py for more details on all of its features.
beeper.py is a work-in-progress library for quickly playing ui beeps. It works by using a static, pre-generated sin wave, along with memoryview objects, to quickly generate your requested frequencies with little ram usage.
Unfortunately, the current implementation is somewhat broken. I think the issue may be caused by the fact that the library is using 8-bit numbers, but the sound driver expects 16-bit numbers. I'm not certain about that though.
For the time being, beeper.py DOES work, and it does seem to be nice and fast, but it also generates some weird glitchy/staticy sounds, and the resulting "notes" are out of tune.
To use it:
from lib import beeper
#init the beeper!
beep = beeper.Beeper()
beep.play(
notes='C4 D4 D4', # a string containing notes to play, from C3 to D6 or '-' for a pause, separated by spaces.
length_seconds=0.12, # how long to play each note
volume=2) # an integer from 0-10 representing the volume of the playback. Default is 2, 0 is almost inaudible, 10 is very loud.