Giter Club home page Giter Club logo

arduino-async-macros's Introduction

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));
}

arduino-async-macros's People

Contributors

nosknut avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.