Created
October 10, 2024 17:27
-
-
Save mattgaidica/afbbaa4320ce4b716b4d97a0491ed5fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define GPIO_SENSOR_PIN GPIO_NUM_18 // GPIO pin connected to the sensor | |
#define RTC_GPIO_INDEX 18 // Serial.println(rtc_io_number_get(GPIO_SENSOR_PIN)); | |
#define LED_PIN GPIO_NUM_13 | |
#define LED_GPIO_INDEX 13 | |
const ulp_insn_t ulp_program[] = { | |
// Main loop | |
M_LABEL(1), | |
// Read GPIO18 state (bit 28) via RTC_GPIO_IN_REG | |
I_RD_REG(RTC_GPIO_IN_REG, RTC_GPIO_INDEX + RTC_GPIO_IN_NEXT_S, RTC_GPIO_INDEX + RTC_GPIO_IN_NEXT_S), | |
// If GPIO18 is HIGH, turn OFF the LED (connected to GPIO19) | |
M_BG(2, 0), // If R0 > 0 (GPIO18 is HIGH), branch to label 2 | |
// GPIO18 is LOW, turn ON the LED (connected to GPIO19, bit 19) | |
I_WR_REG(RTC_GPIO_OUT_REG, LED_GPIO_INDEX + RTC_GPIO_OUT_DATA_S, LED_GPIO_INDEX + RTC_GPIO_OUT_DATA_S, 1), // Set GPIO19 to HIGH (LED ON) | |
M_BX(1), // Loop back to label 1 | |
// Label 2: GPIO18 is HIGH, turn OFF the LED | |
M_LABEL(2), | |
I_WR_REG(RTC_GPIO_OUT_REG, LED_GPIO_INDEX + RTC_GPIO_OUT_DATA_S, LED_GPIO_INDEX + RTC_GPIO_OUT_DATA_S, 0), // Set GPIO19 to LOW (LED OFF) | |
M_BX(1), // Loop back to label 1 | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment