The E Ink display on Badger 2040 supports several update speeds. These can be set using `update_speed(speed)` where `speed` is a value from `0` to `3`. For convenience these speeds have been given the following constants:
Badger 2040 features five buttons on its front, labelled A, B, C, ↑ (up), ↓ (down), and 1 button on the rear labelled BOOT/USR. These can be read using the `pressed(button)` function, which accepts the button's pin number. For convenience, each button can be referred to using these constants:
The system clock speed of the RP2040 can be controlled, allowing power to be saved if on battery, or faster computations to be performed. Use `badger2040.system_speed(speed)` where `speed` is one of the following constants:
It is best to set the clock speed as the first thing in your program, and you must not change it after initializing any drivers for any I2C hardware connected to the qwiic port. To allow you to set the speed at the top of your program, this method is on the `badger2040` module, rather than the `badger` instance, although we have made sure that it is safe to call it after creating a `badger` instance.
Note that `SYSTEM_TURBO` overclocks the RP2040 to 250MHz, and applies a small over voltage to ensure this is stable. We've found that every RP2040 we've tested is happy to run at this speed without any issues.
There are 16 pen colours - or "shades of grey" - to choose, from 0 (black) to 15 (white).
Since Badger2040 cannot display colours other than black and white, any value from 1 to 14 will apply dithering when drawn, to simulate a shade of grey.
```python
pen(
colour # int: colour from 0 to 15
)
```
### Pen Thickness
Thickness governs how thick a line should be and affects lines and text making them thicker or bolder respectively:
```python
thickness(
value # int: thickness in pixels
)
```
## Text
### Draw Text
To draw text in your selected font:
```python
text(
text, # string: the text to draw
x, # int: x coordinate for the left middle of the text
y, # int: y coordinate for the left middle of the text
scale=1.0, # float: size of the text
rotation=0.0 # float: rotation of the text in degrees
)
```
Text uses the "thickness" value, too, and a larger thickness value will give you bold text.
### Measure Text
Sometimes it's useful to know how big a particular bit of text will be on the screen. You can measure it like so:
There are also three bitmap fonts, useful for smaller text and retro goodness. They should handle characters like £, ° and accented characters more gracefully.
The basic building blocks of any Badger2040 interface are lines and rectangles.
### Pixel
Single pixels are always drawn in your pen colour, and with the thickness set by `thickness`.
Be wary that colours other than 0 and 15 can result in your pixel being dithered, and invisible! Badger2040 cannot draw just *one* grey pixel, sorry.
```python
pixel(
x, # int: x coordinate of pixel to draw
y # int: y coordinate of pixel to draw
)
```
### Line
Lines are always drawn in your pen colour, and with the line thickness set by `thickness`.
```python
line(
x1, # int: x coordinate of starting point
y1, # int: y coordinate of starting point
x2, # int: x coordinate of ending point
y2, # int: y coordinate of ending point
)
```
### Rectangle
Rectangles are always drawn in your pen colour.
They are the best way to see the dithering effects of different pens since anything from 1 to 14 (ie: not full black or white) is dithered.
```python
rectangle(
x, # int: x coordinate of the rectangle's top left corner
y, # int: y coordinate of the rectangle's top left corner
w, # int: width of rectangle
h # int: height of rectangle
)
```
## Images
Must be a multiple of 8 pixels wide (because reasons).
You will normally be using a `bytearray` as your source of data.
To load an image you must first allocate a `bytearray` big enough to store it. The formula is `WIDTH * HEIGHT / 8` since there are eight image pixels in every byte (one bit per pixels indicating either 1 black or 0 white):
```python
my_image = bytearray(int(296 * 128 / 8))
```
You can then open your file and read it into your `bytearray`:
```python
open("my_image.bin", "r").readinto(my_image)
```
And finally display it:
```python
screen = badger2040.Badger2040()
screen.image(my_image)
screen.update()
```
### Converting Images
We've supplied a script - `convert.py` - which will help you get your images converted.