Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update asyncio_simpletest.py #61

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
43 changes: 42 additions & 1 deletion examples/asyncio_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries

Check failure on line 1 in examples/asyncio_simpletest.py

View workflow job for this annotation

GitHub Actions / test

reformatted
# SPDX-FileCopyrightText: Copyright (c) 2021 Dan Halbert for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
# Contributor: Sean Carney

"""
Example that illustrates how to use asyncio to execute two functions at
user-defined time intervals.
"""

# Imports
import asyncio
from adafruit_ticks import ticks_ms, ticks_diff

async def function_1():
print('Execturing function_1')
await asyncio.sleep(0)

async def function_2():
print('Execturing function_2')
await asyncio.sleep(0)

async def main():

# Desired time delays in milliseconds
delay_1 = 1000
delay_2 = 100

# Set start of frame
start_function_1 = ticks_ms()
start_function_2 = ticks_ms()

while True:

if ticks_diff(ticks_ms(), start_function_1 ) > delay_1:
start_function_1 = ticks_ms()
asyncio.create_task(function_1())

if ticks_diff(ticks_ms(), start_function_2) > delay_2:
start_function_2 = ticks_ms()
asyncio.create_task(function_2())

await asyncio.sleep(0)

asyncio.run(main())
Loading