diff options
author | Eddy Pedroni <epedroni@pm.me> | 2025-10-02 10:36:39 +0200 |
---|---|---|
committer | Eddy Pedroni <epedroni@pm.me> | 2025-10-02 10:36:39 +0200 |
commit | e55860e32a625a22b1d0fad8cd5a328e3aa3aaa6 (patch) | |
tree | 9f89401f5e2faa39da3036fc9aae7ecceb44a9bc /power-seq-software-seeed-rp2040/power-seq-software-seeed-rp2040.cpp | |
parent | e37d62700d05c7a4a57c100a32e50cc2d94e3c2a (diff) |
Diffstat (limited to 'power-seq-software-seeed-rp2040/power-seq-software-seeed-rp2040.cpp')
-rw-r--r-- | power-seq-software-seeed-rp2040/power-seq-software-seeed-rp2040.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/power-seq-software-seeed-rp2040/power-seq-software-seeed-rp2040.cpp b/power-seq-software-seeed-rp2040/power-seq-software-seeed-rp2040.cpp new file mode 100644 index 0000000..f81c1dd --- /dev/null +++ b/power-seq-software-seeed-rp2040/power-seq-software-seeed-rp2040.cpp @@ -0,0 +1,53 @@ +#include <cstddef> +#include <cstdint> +#include <array> +#include "pico/stdlib.h" +#include "pico/sleep.h" +#include "hardware/gpio.h" + +#define PIN0 26 +#define PIN1 27 +#define PIN2 28 +#define PIN3 29 +#define PIN4 6 + +static constexpr std::size_t button_gpio = PIN4; +static constexpr std::size_t led_gpio = PIN0; +static constexpr std::array<std::size_t, 3> gpio_on_sequence { PIN1, PIN2, PIN3 }; +static constexpr std::array<std::size_t, 3> gpio_off_sequence { PIN3, PIN2, PIN1 }; +static constexpr std::size_t delay_ms = 2000; + +int main() +{ + bool state = false; + + // init LED + gpio_init(led_gpio); + gpio_set_dir(led_gpio, GPIO_OUT); + gpio_put(led_gpio, state); + + // init relay GPIOs + for (auto const & relay : gpio_off_sequence) + { + gpio_init(relay); + gpio_set_dir(relay, GPIO_OUT); + gpio_put(relay, state); + } + + while (true) + { + sleep_run_from_xosc(); + sleep_goto_dormant_until_edge_high(button_gpio); + sleep_power_up(); + + state = !state; + gpio_put(led_gpio, state); + + auto const & sequence = state ? gpio_on_sequence : gpio_off_sequence; + for (auto const & relay : sequence) + { + gpio_put(relay, state); + sleep_ms(delay_ms); + } + } +} |