import { GPIO } from "./pins" console.log(`kill -9 ${process.pid}`) const gpio = new GPIO({ resetOnClose: true }) // // Blink an LED using led = gpio.output(21) // Read a button using inputs = gpio.inputGroup({ button: { pin: 20, pull: "up", debounce: 10 }, switch: { pin: 16, pull: "up", debounce: 10 } }) led.value = inputs.pins.button.value const iteratorEvents = new Promise(async (resolve) => { for await (const event of inputs.events()) { if (event.pin === "button") { led.value = event.value } } }) const switchEvent = new Promise(async (resolve) => { await inputs.pins.switch.waitForValue(0) console.log("Switch pressed!") resolve() }) process.on("SIGINT", () => { inputs.close() led.close() process.exit(0) }) process.on("SIGTERM", () => { inputs.close() process.exit(0) }) await Promise.race([iteratorEvents, switchEvent]) console.log(`👋 Goodbye!`)