Git Product home page Git Product logo

asyncino's Introduction

.github/workflows/lint.yaml

                               _
  ____ ________  ______  _____(_)___  ____
 / __ `/ ___/ / / / __ \/ ___/ / __ \/ __ \
/ /_/ (__  ) /_/ / / / / /__/ / / / / /_/ /
\__,_/____/\__, /_/ /_/\___/_/_/ /_/\____/
          /____/

An asynchronous library for the Arduino family. Examples



Feature ASYNCINO_DELAY

Enables the usage of the asynchronous delay(callback, milliseconds) and delayMicroseconds(callback, microseconds) functions.

Arduino Reference

https://www.arduino.cc/reference/en/language/functions/time/delay/
https://www.arduino.cc/reference/en/language/functions/time/delaymicroseconds/

Settings

ASYNCINO_DELAY_POOL: the maximum amount of concurrent delays. (default: 1)

Usage

#define ASYNCINO_DELAY

#include "asyncino.h"

void setup() {
    Serial.println("Hello World");

    delay([]() {
        Serial.println("1s later: Hello World");
        delay([]() {
            Serial.println("1.5s later: Hello World");
        }, 500);
    }, 1000);
    
    delay([]() {
        Serial.println("0.5s later: Hello World");
    }, 500);
}

void loop() {
    asyncino();
}


Feature ASYNCINO_PULSEIN

Enables the usage of the asynchonous pulseIn(callback, port, value, timeout?) and pulseInLong(callback, port, value, timeout?) functions.

Arduino Reference

https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/
https://www.arduino.cc/reference/en/language/functions/advanced-io/pulseinlong/

Settings

ASYNCINO_PULSEIN_POOL: the maximum amount of concurrent pulseIns. (default: 1)

Usage

#define ASYNCINO_PULSEIN

#include "asyncino.h"

void setup() {
    pinMode(7, INPUT_PULLUP);
    // waits for pulse (HIGH => LOW: start timer, LOW => HIGH: stop timer)
    pulseIn([](unsigned long duration) {
        Serial.println("pin 7 received a pulse: " + String(duration) + "us");
    }, 7, LOW);
}

void loop() {
    asyncino();
}


Feature ASYNCINO_ID

Enables the usage of ids, which can be used to clear delays and pulseIns. (clearDelay(id), clearPulseIn(id))

Settings

ASYNCINO_ID_POOL: the size of the free id ring buffer. (default: ASYNCINO_PULSEIN_POOL + ASYNCINO_DELAY_POOL)

Usage

#define ASYNCINO_ID
#define ASYNCINO_DELAY

#include "asyncino.h"

void setup() {
    const AId myDelay = delay([]() {
        Serial.println("MyDelay was executed"); // This should not be printed
    }, 2000);

    delay([]() {
        Serial.println("MyDelay was cleared");
        clearDelay(myDelay); // Cancels a pending delay
    }, 1000);
}

void loop() {
    asyncino();
}


Feature ASYNCINO_LISTEN

Enables the usage of listen(cb, port, type), which can be used to listen for certain changes on a pin.

type can be one of the following:

value constant description
0 ALISTEN_LOW run cb whenever pin is LOW
1 ALISTEN_HIGH run cb whenever pin is HIGH
2 ALISTEN_FALLING run cb whenever pin goes from HIGH to LOW
3 ALISTEN_RISING run cb whenever pin goes from LOW to HIGH
4 ALISTEN_CHANGE run cb whenever pin value changes (RISING or FALLING)

Settings

ASYNCINO_LISTEN_POOL: the maximum amount of concurrent listens. (default: 1)

Usage

#define ASYNCINO_LISTEN

#include "asyncino.h"

void setup() {
    pinMode(7, INPUT_PULLUP);

    // watch pin 7 for changes
    listen([](int value) {
        Serial.println("PIN CHANGED: " + String(value));
    }, 7, ALISTEN_CHANGE); 
}

void loop() {
    asyncino();
}


© Copyright 2023 Lucas Birkert, all rights reserved

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.