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:
*`BUTTON_A` = `12`
*`BUTTON_B` = `13`
*`BUTTON_C` = `14`
*`BUTTON_UP` = `15`
*`BUTTON_DOWN` = `11`
*`BUTTON_USER` = `23`
Note, due to the BOOT/USR button performing both BOOT and USER functions, the output of reading it with `pressed()` will be inverted from the others.
## Other Functions
Below is a list of other functions that have been made available, to help with the creation of more advanced programs.
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:
```python
measure_text(
text, # string: the text to measure
scale # float: size of the text
)
```
### Change Font
There are five fonts to pick from:
* "sans"
* "gothic"
* "cursive"
* "serif"
* "serif_italic"
```python
font(
font # string: one of the fonts listed above
)
```
## Lines, Pixels & Rectangles
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.