Example: Button Interrupt with Dynamic Callbacks #include <stdio.h> #include <stdint.h> // Define a callback type typedef void (*ButtonCallback)(void); // Global variables volatile uint8_t button_pressed_flag = 0; ButtonCallback button_callback = NULL; // ISR: fast, only sets flag void BUTTON_IRQHandler(void) { button_pressed_flag = 1; } // Register a callback dynamically void register_button_callback(ButtonCallback cb) { button_callback = cb; } // Two possible actions void turn_on_led(void) { printf("LED turned ON!\n"); } void send_message(void) { printf("Message sent!\n"); } int main() { // At runtime, we can decide which action to use int user_choice; while (1) { printf("Choose action: 1=LED, 2=Message: "); scanf("%d", &user_choice); if (user_choice == 1) register_button_callback(turn_on_led); // set LED action else register_button...
Are you struggling with a board Wemos D1 (ESP8266 MOD) and testing a servo motor? If the answer is yes, it is the right place to help you out. 1. Set up the board Just follow the step-by-step instructions in this link: https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/ 2. Hardware wiring Same as Arduino Uno. Please note that the servo motor requires an external power supply. https://docs.arduino.cc/learn/electronics/servo-motors/ 3. Open an example "Servo" 4. Select the right board with the right serial port Board: NodeMCU 1.0 (ESP-12E Module) 5. Run an example and contact me if the problem isn't solved. I bet that you know how to run it