summaryrefslogtreecommitdiffstats
path: root/power-seq-software/power-seq-software.cpp
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2025-08-24 22:01:32 +0200
committerEddy Pedroni <epedroni@pm.me>2025-08-24 22:01:32 +0200
commit5b1e60fb5f4d65d14e5dd2a5a4e8ac4a95d3b8cf (patch)
tree695b3eb6c0e8bd32859edf60807dd786fa40d5fb /power-seq-software/power-seq-software.cpp
Initial commit, Raspberry pi pico software implementation
Diffstat (limited to 'power-seq-software/power-seq-software.cpp')
-rw-r--r--power-seq-software/power-seq-software.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/power-seq-software/power-seq-software.cpp b/power-seq-software/power-seq-software.cpp
new file mode 100644
index 0000000..cb10215
--- /dev/null
+++ b/power-seq-software/power-seq-software.cpp
@@ -0,0 +1,47 @@
+#include <cstddef>
+#include <cstdint>
+#include <array>
+#include "pico/stdlib.h"
+#include "pico/sleep.h"
+#include "hardware/gpio.h"
+
+static constexpr std::size_t button_gpio = 6;
+static constexpr std::size_t led_gpio = 2;
+static constexpr std::array<std::size_t, 3> gpio_on_sequence { 3, 4, 5 };
+static constexpr std::array<std::size_t, 3> gpio_off_sequence { 5, 4, 3 };
+static constexpr std::size_t delay_ms = 100;
+
+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);
+ }
+ }
+}