Skip to content

nosknut/arduino-async-macros

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Async Macros

A zero cost abstraction for asynchronous arduino code without using threads or complex switch statements.

Check out the API docs for a more detailed breakdown of the different functions.

Results

Pros

  • Cleaner code

Drawbacks

  • IDE compiler error highlighting is broken
    • Any bugs will be fed through the macro, and so the only way to see errors is in the compiler logs.

Example

void updateMainSequence()
{
    asyncBegin({
        asyncRun({
            Serial.println("Step 0");
        });

        asyncDelay(1000);

        asyncRun({
            Serial.println("Step 1");
        });

        asyncDelay(1000);

        asyncVariable(float, timesRan, 0);

        asyncWhile(timesRan < 10, {
            asyncRun({
                timesRan += 0.5;
                Serial.print("Times ran: ");
                Serial.println(timesRan);
            });
            asyncDelay(500);
        });

        asyncFor(int, i, 0, i <= 5, i++, {
            asyncRun({
                Serial.println(i);
            });
            asyncDelay(1000);
        });

        asyncWhile(!digitalRead(BUTTON_PIN), {
            asyncRun({
                // This sub-sequence will run only
                // when this while loop is active.
                asyncBegin({
                    asyncRun({
                        Serial.println("Waiting for button press");
                    });
                    asyncDelay(1000);
                });
            });
        });
    });
}

void loop()
{
    updateMainSequence();

    digitalWrite(LED_PIN, digitalRead(BUTTON_PIN));
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published