> ## Documentation Index
> Fetch the complete documentation index at: https://launchpad.anxlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Blinky: Your First ANX Dev Module Program

> Build and flash the Blinky example to blink the onboard LED, verify your ANX toolchain setup, and learn the basic ANX SDK application structure.

Blinky is the canonical first program for any hardware platform — it blinks the onboard LED at 1 Hz and confirms that your toolchain, USB connection, and firmware image are all correctly set up. If Blinky runs, your environment is ready for everything else in the ANX SDK.

## 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 standard `main()` 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 --version` should 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.

```c blinky.c theme={null}
#include "anx/anx.h"
#include "anx/gpio.h"

// Onboard LED is connected to GPIO0
#define LED_PIN  0

void app_main(void) {
    // Configure GPIO0 as output
    anx_gpio_set_direction(LED_PIN, ANX_GPIO_OUTPUT);

    while (1) {
        anx_gpio_write(LED_PIN, 1);   // LED on
        anx_delay_ms(500);            // wait 500 ms
        anx_gpio_write(LED_PIN, 0);   // LED off
        anx_delay_ms(500);            // wait 500 ms
    }
}
```

## 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.

<Accordion title="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.
</Accordion>

<Accordion title="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.
</Accordion>

<Accordion title="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.
</Accordion>

<Accordion title="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.
</Accordion>

## Build and Flash

With your module connected via USB, run the following command from the root of the examples repository:

```bash theme={null}
anx run examples/blinky
```

The CLI compiles the application, packages the firmware image, and flashes it over USB in a single step. After the module resets, you should see the onboard LED begin toggling and the following line appear in the serial output:

```
[INFO] Blinky started. LED toggling at 1 Hz.
```

Open the serial monitor at any time to view log output:

```bash theme={null}
anx monitor
```

## 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 to `100` produces a fast strobe effect; increasing them to `2000` gives a slow, lazy pulse:

```c theme={null}
anx_delay_ms(100);   // fast — 5 Hz blink
// or
anx_delay_ms(2000);  // slow — 0.25 Hz blink
```

**Control an external LED** by changing `LED_PIN` to any available GPIO number and wiring an LED with a 330 Ω current-limiting resistor between that pin and GND:

```c theme={null}
#define LED_PIN  5   // use GPIO5 for an external LED
```

Re-flash after each change with `anx run examples/blinky` to see your results immediately.

<Tip>
  Ready to go further? The [Sensor Data](/examples/sensor-data) example builds on the same application structure to read an analog potentiometer over ADC and a temperature/humidity sensor over I2C — no new toolchain steps required.
</Tip>
