This library offers convenient functions for interacting with [Automation 2040 W](https://shop.pimoroni.com/products/automation-2040-w) and [Automation 2040 W Mini](https://shop.pimoroni.com/products/automation-2040-w-mini) - all-in-one, Pico W powered industrial/automation controllers with 2.4GHz wireless connectivity, relays and a plethora of inputs and outputs.
The `Automation2040W` and `Automation2040WMini` classes deal with the initialisation of each of the board's functions. To create one, import the `automation` module, then define a new `board` variable:
From here, all features can be accessed by calling functions on `board`. In addition, when using Qwiic / Stemma QT devices, the I2C channel to use can be accessed with `board.i2c`.
Automation 2040 W Mini has the same pinout as Automation 2040 W, but with fewer inputs, outputs and relays.
Automation 2040 W has two handy switches onboard with neighbouring LEDs, offering a tactile way to interact with your program and be notified of actions that need attention.
To read one of the switches, call `.switch_pressed(switch)`, where `switch` is a value from `0` to `.NUM_SWITCHES - 1`. This returns `True` when the specified switch is pressed, and `False` otherwise.
To set a switch's neighbouring LED, call `.switch_led(switch, brightness)`, where `switch` is a value from `0` to `.NUM_SWITCHES - 1`, and `brightness` is either `True`, `False`, or a number from `0.0` to `100.0`.
Three relays are featured on Automation 2040 W (one on the Mini version). By default these are in a released state, which connects the terminal labelled `NC` to `COM`. By actuating them, a connection from `NO` to `COM` can be made instead.
A relay can be actuated by calling `.actuate_relay(relay)`, or released by calling `.release_relay(relay)`. Additionally the actuated state can be set by providing a boolean to the `actuate` parameter of `.relay(relay, actuate)`.
The state of each relay can be read by calling `.relay(relay)`. This returns `True` if the relay is actuated, and `False` if it is released. The actuation state is also reflected by LEDs that neighbour each relay.
For all these functions, `relay` is a value from `0` to `.NUM_RELAYS - 1`. To control a specific relay, the `automation` module contains these handy constants:
An output can be controlled by calling `.output(output, value)`, where `output` is a value from `0` to `.NUM_OUTPUTS - 1`, and `value` is `True`, `False` or a number between `0.0` and `100.0`
The state of an output can be read by calling `.output(output)`, where `output` is a value from `0` to `.NUM_OUTPUTS - 1`. This returns `True` if the output is on by any percent, or `False` if it is off. The state is also reflected by LEDs that neighbour each output terminal.
If you prefer to know the current PWM setting of an output as a percentage, this can be accessed by calling `.output_precent(output)`, where `output` is a value from `0` to `.NUM_OUTPUTS - 1`. This will return a float between `0.0` and `100.0`.
#### Changing the frequency
The PWM frequency of the output can be set by calling `.change_output_freq(output, freq)`, where `output` is a value from `0` to `.NUM_OUTPUTS - 1` and `freq` is a frequency in Hz between `10.0` and `1000.0`. Values outside of this range will cause a `ValueError`.
Automation 2040 W has four buffered digital inputs (two on the Mini version). These can be read by calling `.read_input(input)`, where `input` is a value from `0` to `.NUM_INPUTS - 1`.
Automation 2040 W has three analog inputs, capable of reading up to 40V. The voltage on these can be read by calling `.read_adc(adc)`, where `adc` is a value from `0` to `.NUM_ADCS - 1`.
On the left hand side of Automation 2040 W are three GPIO pins. These are 3.3V logic only, and are connected to GP0, GP1, and GP2 of the Pico W. These pins can be referenced in code using `0`, `1`, and `2`, or by one of these handy constants on the `automation` module:
If there is a need to put Automation 2040 W back into a known safe-state, without resorting to the hardware reset switch, then `.reset()` can be called. This deactivates all outputs, releases all relays, and turns off all user-controllable LEDs.