diff --git a/examples/emulator.cpp b/examples/emulator.cpp new file mode 100644 index 0000000..5059241 --- /dev/null +++ b/examples/emulator.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include + +bool running = true; + +void signal_handler(int signum) { + running = false; +} + +int main() { + const int PIN_HOLD = 17; // stays ON + const int PIN_BLINK = 27; // toggles + const double ON_INTERVAL = 0.2; // seconds ON + const double OFF_INTERVAL = 0.8; // seconds OFF + + signal(SIGINT, signal_handler); + + int pi = pigpio_start(NULL, NULL); + if (pi < 0) { + std::cerr << "Failed to connect to pigpiod daemon.\n"; + return 1; + } + + + set_mode(pi, PIN_HOLD, PI_OUTPUT); + set_mode(pi, PIN_BLINK, PI_OUTPUT); + + gpio_write(pi, PIN_HOLD, 1); + std::cout << "GPIO " << PIN_HOLD << " ON (constant), toggling GPIO " << PIN_BLINK << "...\n"; + + while (running) { + gpio_write(pi, PIN_BLINK, 1); + std::this_thread::sleep_for(std::chrono::duration(ON_INTERVAL)); + gpio_write(pi, PIN_BLINK, 0); + std::this_thread::sleep_for(std::chrono::duration(OFF_INTERVAL)); + } + + std::cout << "\nStopping...\n"; + gpio_write(pi, PIN_HOLD, 0); + gpio_write(pi, PIN_BLINK, 0); + pigpio_stop(pi); + + return 0; +} \ No newline at end of file diff --git a/settings.txt b/settings.txt index 5f86687..324217e 100644 --- a/settings.txt +++ b/settings.txt @@ -132,7 +132,7 @@ # # #!/bin/bash # if [ -f app.pid ]; then -# kill $(cat app.pid) +# kill -INT $(cat app.pid) # rm app.pid # fi #