What You’ll Learn
Working through this example gives you hands-on experience with three fundamental building blocks of every ANX application:- ANX SDK application entry point — how
app_main()replaces the standardmain()function in ANX OS - GPIO output control — how to configure a pin direction and drive it high or low
- Task scheduling with delays — how
anx_delay_ms()yields CPU time to other tasks instead of busy-waiting
Prerequisites
Make sure you have the following before you begin:- ANX CLI installed and available on your
PATH(anx --versionshould print a version string) - ANX OS firmware flashed to your dev module (any version 1.0.0 or later)
- ANX dev module connected to your computer via USB
Application Code
The complete Blinky application is fewer than 20 lines of C. Every line is annotated so you can follow exactly what happens from power-on to the first LED toggle.blinky.c
Code Walkthrough
Each function in the example maps to a distinct concept in the ANX SDK. Understanding these four building blocks will carry over into every other example and project you build.app_main() — the application entry point
app_main() — the application entry point
ANX OS calls
app_main() after the kernel and all built-in drivers have finished initializing. You never write a main() function in an ANX application — the OS owns that symbol and uses it to set up the scheduler, memory allocator, and peripheral clocks before handing control to your code.anx_gpio_set_direction() — configuring pin mode
anx_gpio_set_direction() — configuring pin mode
Before you can drive a GPIO pin, you must declare its direction.
anx_gpio_set_direction(pin, mode) accepts either ANX_GPIO_OUTPUT or ANX_GPIO_INPUT. Calling this function on a pin that is already configured as an output is safe and idempotent — the hardware register is simply written with the same value.anx_gpio_write() — setting the logic level
anx_gpio_write() — setting the logic level
anx_gpio_write(pin, level) drives the specified pin to a logic high (1) or logic low (0). On the ANX dev module, the onboard LED is active-high, so writing 1 turns it on and writing 0 turns it off. If you connect an external LED with a current-limiting resistor, the same logic applies.anx_delay_ms() — yielding to other tasks
anx_delay_ms() — yielding to other tasks
Unlike a busy-wait loop,
anx_delay_ms(ms) suspends the current task and returns CPU time to the ANX OS scheduler for the specified number of milliseconds. Other tasks — logging, USB communication, a background watchdog — continue to run during the delay. This makes your application cooperative and efficient even in a tight blink loop.Build and Flash
With your module connected via USB, run the following command from the root of the examples repository:Modifying the Example
Once Blinky is running, try a few quick changes to deepen your understanding of the GPIO and delay APIs. Change the blink speed by adjusting the delay values. Cutting both delays to100 produces a fast strobe effect; increasing them to 2000 gives a slow, lazy pulse:
LED_PIN to any available GPIO number and wiring an LED with a 330 Ω current-limiting resistor between that pin and GND:
anx run examples/blinky to see your results immediately.