Skip to content

aalec

AALeC library implementation.

This class tries to implement the same API as the arduino version of this library. The original implementation can be found here: AALeC-V3.

Attention

Some changes:

  • This library works only for the BMP280 environment sensor.
  • The Wii-Nunchuck controller is not implemented.

Modules:

Name Description
beeper

Beeper utilities.

button

Button Utilities.

constants

All the constants of this library.

display

Display utilities.

encoder

Encoder utility.

environment

Environment utilities.

rgb_strip

RGB Strip utilities.

third_party

External libraries that are shipt here directly for convenance sake.

Classes:

Name Description
AALeC

Proxy class to implement the AALeC API.

AALeC

AALeC()

Proxy class to implement the AALeC API.

Methods:

Name Description
button_changed
clear_display
draw_progressbar
filled_rect

Proxy for Display.filled_rect.

get_analog

Get value from analog pin.

get_button

Proxy for Button.get_button.

get_environment_sensor
get_gas_resistance
get_humidity
get_pressure
get_rotate

Proxy for Encoder.get_rotate.

get_temp
id

A unique ID for this board.

play

Proxy for Beeper.play.

print_line

Proxy for Display.print_line.

rect

Proxy for Display.rect.

reset_rgb_strip

Proxy for RgbStrip.reset.

reset_rotate
rotate_changed
set_rgb_led
set_rgb_strip
Source code in src/aalec/__init__.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def __init__(self):
    self._adc = machine.ADC(0)
    self._beeper = beeper.Beeper(constants.PIN_BEEPER)
    self._button = button.Button(constants.PIN_BUTTON)
    self._i2c = machine.I2C(
        sda=machine.Pin(constants.PIN_SDA), scl=machine.Pin(constants.PIN_SCL)
    )
    self._display = display.Display(self._i2c)
    self._encoder = encoder.Encoder(
        constants.PIN_ENCODER_TRACK_1, constants.PIN_ENCODER_TRACK_2
    )
    self._environment = environment.Environment(self._i2c, constants.BMP280_ADDR)
    self._rgb_strip = rgb_strip.RgbStrip(
        constants.PIN_RGB_STRIP, constants.LED_COUNT
    )

button_changed

button_changed() -> bool

Proxy for Button.button_change.

Returns:

Name Type Description
bool bool

True if the value has changed since the last call. False otherwise.

Source code in src/aalec/__init__.py
78
79
80
81
82
83
84
def button_changed(self) -> bool:
    """Proxy for [`Button.button_change`](button.md#aalec.button.Button.button_changed).

    Returns:
        bool: `True` if the value has changed since the last call. `False` otherwise.
    """
    return self._button.button_changed()

clear_display

clear_display() -> None

Proxy for Display.clear_display.

Source code in src/aalec/__init__.py
97
98
99
def clear_display(self) -> None:
    """Proxy for [`Display.clear_display`](display.md#aalec.display.Display.clear_display)."""
    self._display.clear_display()

draw_progressbar

draw_progressbar(
    x: int, y: int, width: int, height: int, percent: int
) -> None

Proxy for Display.draw_progressbar.

Parameters:

Name Type Description Default
x int

X coordinate of the upper left corner of the progressbar

required
y int

Y coordinate of the upper left corner of the progressbar

required
width int

Width of the progressbar in pixel. (x delta to the lower right corner.)

required
height int

Height of the progressbar in pixel. (y delta to the lower right corner.)

required
percent int

How many percent the bar is filled (grows to the right).

required
Source code in src/aalec/__init__.py
125
126
127
128
129
130
131
132
133
134
135
136
137
def draw_progressbar(
    self, x: int, y: int, width: int, height: int, percent: int
) -> None:
    """Proxy for [`Display.draw_progressbar`](display.md#aalec.display.Display.draw_progressbar).

    Args:
        x (int): X coordinate of the upper left corner of the progressbar
        y (int): Y coordinate of the upper left corner of the progressbar
        width (int): Width of the progressbar in pixel. (x delta to the lower right corner.)
        height (int): Height of the progressbar in pixel. (y delta to the lower right corner.)
        percent (int): How many percent the bar is filled (grows to the right).
    """
    self._display.draw_progressbar(x, y, width, height, percent)

filled_rect

filled_rect(
    x: int, y: int, width: int, height: int, color: int
) -> None

Proxy for Display.filled_rect.

Parameters:

Name Type Description Default
x int

X coordinate of the upper left corner of the progressbar

required
y int

Y coordinate of the upper left corner of the progressbar

required
width int

Width of the progressbar in pixel. (x delta to the lower right corner.)

required
height int

Height of the progressbar in pixel. (y delta to the lower right corner.)

required
color int

Fill color (constants.WHITE or constants.BLACK)

required
Source code in src/aalec/__init__.py
113
114
115
116
117
118
119
120
121
122
123
def filled_rect(self, x: int, y: int, width: int, height: int, color: int) -> None:
    """Proxy for [`Display.filled_rect`](display.md#aalec.display.Display.filled_rect).

    Args:
        x (int): X coordinate of the upper left corner of the progressbar
        y (int): Y coordinate of the upper left corner of the progressbar
        width (int): Width of the progressbar in pixel. (x delta to the lower right corner.)
        height (int): Height of the progressbar in pixel. (y delta to the lower right corner.)
        color (int): Fill color (`constants.WHITE` or `constants.BLACK`)
    """
    self._display.filled_rect(x, y, width, height, color)

get_analog

get_analog() -> int

Get value from analog pin.

Returns:

Name Type Description
int int

Value of the 10 bit ADC (0-1024)

Source code in src/aalec/__init__.py
52
53
54
55
56
57
58
def get_analog(self) -> int:
    """Get value from analog pin.

    Returns:
        int: Value of the 10 bit ADC (0-1024)
    """
    return self._adc.read()

get_button

get_button() -> int

Proxy for Button.get_button.

Returns:

Name Type Description
int int

Value of the button. Button pressed: 1. Button released: 0.

Source code in src/aalec/__init__.py
70
71
72
73
74
75
76
def get_button(self) -> int:
    """Proxy for [`Button.get_button`](button.md#aalec.button.Button.get_button).

    Returns:
        int: Value of the button. Button pressed: `1`. Button released: `0`.
    """
    return self._button.get_button()

get_environment_sensor

get_environment_sensor() -> str

Proxy for Environment.get_environment_sensor.

Returns:

Name Type Description
str str

"BMP280"

Source code in src/aalec/__init__.py
163
164
165
166
167
168
169
def get_environment_sensor(self) -> str:
    """Proxy for [`Environment.get_environment_sensor`](environment.md#aalec.environment.Environment.get_environment_sensor).

    Returns:
        str: "BMP280"
    """
    return self._environment.get_environment_sensor()

get_gas_resistance

get_gas_resistance() -> float

Proxy for Environment.get_gas_resistance.

Returns:

Name Type Description
float float

0.0 (BMP280 doesn't have a gas resistance sensor).

Source code in src/aalec/__init__.py
195
196
197
198
199
200
201
def get_gas_resistance(self) -> float:
    """Proxy for [`Environment.get_gas_resistance`](environment.md#aalec.environment.Environment.get_gas_resistance).

    Returns:
        float: 0.0 (BMP280 doesn't have a gas resistance sensor).
    """
    return self._environment.get_gas_resistance()

get_humidity

get_humidity() -> float

Proxy for Environment.get_humidity.

Returns:

Name Type Description
float float

0.0 (BMP280 doesn't have a humidity sensor).

Source code in src/aalec/__init__.py
179
180
181
182
183
184
185
def get_humidity(self) -> float:
    """Proxy for [`Environment.get_humidity`](environment.md#aalec.environment.Environment.get_humidity).

    Returns:
        float: 0.0 (BMP280 doesn't have a humidity sensor).
    """
    return self._environment.get_humidity()

get_pressure

get_pressure() -> float

Proxy for Environment.get_pressure.

Returns:

Name Type Description
float float

current pressure in hPa.

Source code in src/aalec/__init__.py
187
188
189
190
191
192
193
def get_pressure(self) -> float:
    """Proxy for [`Environment.get_pressure`](environment.md#aalec.environment.Environment.get_pressure).

    Returns:
        float: current pressure in hPa.
    """
    return self._environment.get_pressure()

get_rotate

get_rotate() -> int

Proxy for Encoder.get_rotate.

Returns:

Name Type Description
int int

Value of the rotary encoder.

Source code in src/aalec/__init__.py
139
140
141
142
143
144
145
def get_rotate(self) -> int:
    """Proxy for [`Encoder.get_rotate`](encoder.md#aalec.encoder.Encoder.get_rotate).

    Returns:
        int: Value of the rotary encoder.
    """
    return self._encoder.get_rotate()

get_temp

get_temp() -> float

Proxy for Environment.get_temp.

Returns:

Name Type Description
float float

Current temperature in °C.

Source code in src/aalec/__init__.py
171
172
173
174
175
176
177
def get_temp(self) -> float:
    """Proxy for [`Environment.get_temp`](environment.md#aalec.environment.Environment.get_temp).

    Returns:
        float: Current temperature in °C.
    """
    return self._environment.get_temp()

id

id() -> str

A unique ID for this board.

Returns:

Name Type Description
str str

The unique ID for this board.

Source code in src/aalec/__init__.py
40
41
42
43
44
45
46
47
48
49
50
def id(self) -> str:
    """A unique ID for this board.

    Returns:
        str: The unique ID for this board.
    """
    # Calculate the ID just like ESP.getChipId() in Arduino.
    chip_id = machine.unique_id()
    chip_id_int = int.from_bytes(chip_id[-3:], "big")

    return f"AALeC-{chip_id_int}"

play

play(freq: int, dur: int | None = None) -> None

Proxy for Beeper.play.

Parameters:

Name Type Description Default
freq int

The frequency of the tone. If the frequency is <=0, no tone will be played.

required
dur int | None

Duration of the tone in ms. If set to None the tone will keep playing. Defaults to None.

None
Source code in src/aalec/__init__.py
60
61
62
63
64
65
66
67
68
def play(self, freq: int, dur: int | None = None) -> None:
    """Proxy for [`Beeper.play`](beeper.md#aalec.beeper.Beeper.play).

    Args:
        freq (int): The frequency of the tone. If the frequency is <=0, no tone will be played.
        dur (int | None, optional): Duration of the tone in ms.
            If set to `None` the tone will keep playing. Defaults to None.
    """
    self._beeper.play(freq, dur)

print_line

print_line(line: int, text: str) -> None

Proxy for Display.print_line.

A line can be at most 16 characters long. (A character has a size of 8x8 pixels.)

Parameters:

Name Type Description Default
line int

Line number. Valid values are from 1 to 5.

required
text str

The content to display.

required
Source code in src/aalec/__init__.py
86
87
88
89
90
91
92
93
94
95
def print_line(self, line: int, text: str) -> None:
    """Proxy for [`Display.print_line`](display.md#aalec.display.Display.print_line).

    A line can be at most 16 characters long. (A character has a size of 8x8 pixels.)

    Args:
        line (int): Line number. Valid values are from 1 to 5.
        text (str): The content to display.
    """
    self._display.print_line(line, text)

rect

rect(
    x: int, y: int, width: int, height: int, color: int
) -> None

Proxy for Display.rect.

Parameters:

Name Type Description Default
x int

X coordinate of the upper left corner of the progressbar

required
y int

Y coordinate of the upper left corner of the progressbar

required
width int

Width of the progressbar in pixel. (x delta to the lower right corner.)

required
height int

Height of the progressbar in pixel. (y delta to the lower right corner.)

required
color int

Frame color (constants.WHITE or constants.BLACK)

required
Source code in src/aalec/__init__.py
101
102
103
104
105
106
107
108
109
110
111
def rect(self, x: int, y: int, width: int, height: int, color: int) -> None:
    """Proxy for [`Display.rect`](display.md#aalec.display.Display.rect).

    Args:
        x (int): X coordinate of the upper left corner of the progressbar
        y (int): Y coordinate of the upper left corner of the progressbar
        width (int): Width of the progressbar in pixel. (x delta to the lower right corner.)
        height (int): Height of the progressbar in pixel. (y delta to the lower right corner.)
        color (int): Frame color (`constants.WHITE` or `constants.BLACK`)
    """
    self._display.rect(x, y, width, height, color)

reset_rgb_strip

reset_rgb_strip() -> None

Proxy for RgbStrip.reset.

Source code in src/aalec/__init__.py
227
228
229
def reset_rgb_strip(self) -> None:
    """Proxy for [`RgbStrip.reset`](rgb_strip.md#aalec.rgb_strip.RgbStrip.reset)."""
    self._rgb_strip.reset()

reset_rotate

reset_rotate(value: int) -> None

Proxy for Encoder.reset_rotate.

Parameters:

Name Type Description Default
value int

new value for the rotary encoder.

required
Source code in src/aalec/__init__.py
155
156
157
158
159
160
161
def reset_rotate(self, value: int) -> None:
    """Proxy for [`Encoder.reset_rotate`](encoder.md#aalec.encoder.Encoder.reset_rotate).

    Args:
        value (int): new value for the rotary encoder.
    """
    self._encoder.reset_rotate(value)

rotate_changed

rotate_changed() -> bool

Proxy for Encoder.rotate_changed.

Returns:

Name Type Description
bool bool

True if the value changed since last call. False otherwise.

Source code in src/aalec/__init__.py
147
148
149
150
151
152
153
def rotate_changed(self) -> bool:
    """Proxy for [`Encoder.rotate_changed`](encoder.md#aalec.encoder.Encoder.rotate_changed).

    Returns:
        bool: True if the value changed since last call. False otherwise.
    """
    return self._encoder.rotate_changed()

set_rgb_led

set_rgb_led(led: int, color: RgbColor) -> None

Proxy for RgbStrip.set_rgb_led.

Parameters:

Name Type Description Default
led int

Index of the led in the strip (starts with 0).

required
color RgbColor

The color to set

required

Raises:

Type Description
AttributeError

If the led value does not address a led in the strip.

Source code in src/aalec/__init__.py
203
204
205
206
207
208
209
210
211
212
213
def set_rgb_led(self, led: int, color: constants.RgbColor) -> None:
    """Proxy for [`RgbStrip.set_rgb_led`](rgb_strip.md#aalec.rgb_strip.RgbStrip.set_rgb_led).

    Args:
        led (int): Index of the led in the strip (starts with 0).
        color (RgbColor): The color to set

    Raises:
        AttributeError: If the `led` value does not address a led in the strip.
    """
    self._rgb_strip.set_rgb_led(led, color)

set_rgb_strip

set_rgb_strip(colors: list[RgbColor]) -> None

Proxy for RgbStrip.set_rgb_strip.

Parameters:

Name Type Description Default
colors list[RgbColor]

A list of colors.

required

Raises:

Type Description
AttributeError

If the length of the list of colors is not exactly the number of leds in the strip.

Source code in src/aalec/__init__.py
215
216
217
218
219
220
221
222
223
224
225
def set_rgb_strip(self, colors: list[constants.RgbColor]) -> None:
    """Proxy for [`RgbStrip.set_rgb_strip`](rgb_strip.md#aalec.rgb_strip.RgbStrip.set_rgb_strip).

    Args:
        colors (list[RgbColor]): A list of colors.

    Raises:
        AttributeError: If the length of the list of colors is not
            exactly the number of leds in the strip.
    """
    self._rgb_strip.set_rgb_strip(colors)