1. 1.
    Trigger the first comparison on the comparator channel.
    ac_chan_trigger_single_shot(&ac_instance, AC_COMPARATOR_CHANNEL);
  2. 2.
    Create a local variable to maintain the current comparator state. Since no comparison has taken place, it is initialized to AC_CHAN_STATUS_UNKNOWN.
    uint8_t last_comparison = AC_CHAN_STATUS_UNKNOWN;
  3. 3.
    Make the application loop infinitely, while performing triggered comparisons.
    while (true) {
  4. 4.
    Check if the comparator is ready for the last triggered comparison result to be read.
    if (ac_chan_is_ready(&ac_instance, AC_COMPARATOR_CHANNEL)) {
  5. 5.
    Read the comparator output state into the local variable for application use, re-trying until the comparison state is ready.
    do {
        last_comparison = ac_chan_get_status(&ac_instance,
    } while (last_comparison & AC_CHAN_STATUS_UNKNOWN);
  6. 6.
    Set the board LED state to mirror the last comparison state.
            (last_comparison & AC_CHAN_STATUS_NEG_ABOVE_POS));
  7. 7.
    Trigger the next conversion on the Analog Comparator channel.
    ac_chan_trigger_single_shot(&ac_instance, AC_COMPARATOR_CHANNEL);