speaker: initial commit
This commit is contained in:
commit
85d9227b91
10 changed files with 317 additions and 0 deletions
147
.gitignore
vendored
Normal file
147
.gitignore
vendored
Normal file
|
@ -0,0 +1,147 @@
|
|||
|
||||
# Created by https://www.gitignore.io/api/python,visualstudiocode
|
||||
# Edit at https://www.gitignore.io/?templates=python,visualstudiocode
|
||||
|
||||
### Python ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
pip-wheel-metadata/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
|
||||
# End of https://www.gitignore.io/api/python,visualstudiocode
|
||||
|
||||
### Micropy Cli ###
|
||||
.micropy/
|
||||
!micropy.json
|
||||
!src/lib
|
22
.pylintrc
Normal file
22
.pylintrc
Normal file
|
@ -0,0 +1,22 @@
|
|||
[MASTER]
|
||||
# Loaded Stubs: esp8266-micropython-1.11.0
|
||||
init-hook='import sys;sys.path[1:1]=["src/lib",".micropy/BradenM-micropy-stubs-c89b5ef/frozen", ".micropy/BradenM-micropy-stubs-e1b8ce6/frozen", ".micropy/BradenM-micropy-stubs-c89b5ef/stubs", ".micropy/speaker", ]'
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
# Only show warnings with the listed confidence levels. Leave empty to show
|
||||
# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED.
|
||||
confidence=
|
||||
|
||||
# Disable the message, report, category or checker with the given id(s). You
|
||||
# can either give multiple identifiers separated by comma (,) or put this
|
||||
# option multiple times (only on the command line, not in the configuration
|
||||
# file where it should appear only once). You can also use "--disable=all" to
|
||||
# disable everything first and then reenable specific checks. For example, if
|
||||
# you want to run only the similarities checker, you can use "--disable=all
|
||||
# --enable=similarities". If you want to run only the classes checker, but have
|
||||
# no Warning level messages displayed, use "--disable=all --enable=classes
|
||||
# --disable=W".
|
||||
|
||||
disable = missing-docstring, line-too-long, trailing-newlines, broad-except, logging-format-interpolation, invalid-name, empty-docstring,
|
||||
no-method-argument, assignment-from-no-return, too-many-function-args, unexpected-keyword-arg
|
||||
# the 2nd line deals with the limited information in the generated stubs.
|
9
.vscode/extensions.json
vendored
Normal file
9
.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
|
||||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
||||
// List of extensions which should be recommended for users of this workspace.
|
||||
"recommendations": [
|
||||
"ms-python.python", // micropy-cli: required for vscode micropython integrations
|
||||
"VisualStudioExptTeam.vscodeintellicode" // micropy-cli: optional for advanced intellisense
|
||||
]
|
||||
}
|
23
.vscode/settings.json
vendored
Normal file
23
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"python.linting.enabled": true,
|
||||
"python.jediEnabled": false,
|
||||
"python.autoComplete.extraPaths": [
|
||||
".micropy/BradenM-micropy-stubs-c89b5ef/frozen",
|
||||
".micropy/BradenM-micropy-stubs-e1b8ce6/frozen",
|
||||
".micropy/BradenM-micropy-stubs-c89b5ef/stubs",
|
||||
".micropy/speaker"
|
||||
],
|
||||
"python.autoComplete.typeshedPaths": [
|
||||
".micropy/BradenM-micropy-stubs-c89b5ef/frozen",
|
||||
".micropy/BradenM-micropy-stubs-e1b8ce6/frozen",
|
||||
".micropy/BradenM-micropy-stubs-c89b5ef/stubs",
|
||||
".micropy/speaker"
|
||||
],
|
||||
"python.analysis.typeshedPaths": [
|
||||
".micropy/BradenM-micropy-stubs-c89b5ef/frozen",
|
||||
".micropy/BradenM-micropy-stubs-e1b8ce6/frozen",
|
||||
".micropy/BradenM-micropy-stubs-c89b5ef/stubs",
|
||||
".micropy/speaker"
|
||||
],
|
||||
"python.linting.pylintEnabled": true
|
||||
}
|
1
dev-requirements.txt
Normal file
1
dev-requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
micropy-cli
|
14
micropy.json
Normal file
14
micropy.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "speaker",
|
||||
"stubs": {
|
||||
"esp8266-micropython-1.11.0": "1.2.0"
|
||||
},
|
||||
"dev-packages": {
|
||||
"micropy-cli": "*"
|
||||
},
|
||||
"packages": {},
|
||||
"config": {
|
||||
"vscode": true,
|
||||
"pylint": true
|
||||
}
|
||||
}
|
21
pymakr.conf
Normal file
21
pymakr.conf
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"address": "/dev/ttyUSB0",
|
||||
"username": "micro",
|
||||
"password": "python",
|
||||
"sync_folder": "src",
|
||||
"open_on_start": true,
|
||||
"safe_boot_on_upload": false,
|
||||
"py_ignore": [
|
||||
"pymakr.conf",
|
||||
".vscode",
|
||||
".gitignore",
|
||||
".git",
|
||||
"project.pymakr",
|
||||
"env",
|
||||
"venv",
|
||||
".python-version",
|
||||
".micropy/",
|
||||
"micropy.json"
|
||||
],
|
||||
"fast_upload": false
|
||||
}
|
0
requirements.txt
Normal file
0
requirements.txt
Normal file
1
src/boot.py
Normal file
1
src/boot.py
Normal file
|
@ -0,0 +1 @@
|
|||
# boot.py - - runs on boot-up
|
79
src/main.py
Normal file
79
src/main.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
# main.py
|
||||
import machine
|
||||
import time
|
||||
|
||||
SND_PIN = 14
|
||||
DUTY = 512
|
||||
|
||||
tones = {
|
||||
"A0": 278, "AIS0": 29, "B0": 31,
|
||||
"C1": 33, "CIS1": 35, "D1": 37, "DIS1": 39, "E1": 41, "F1": 44,
|
||||
"FIS1": 46, "G1": 49, "GIS1": 52, "A1": 55, "AIS1": 58, "H1": 62,
|
||||
"C2": 65, "CIS2": 69, "D2": 73, "DIS2": 77, "E2": 82, "F2": 87,
|
||||
"FIS2": 92, "G2": 98, "GIS2": 104, "A2": 110, "AIS2": 116, "H2": 123,
|
||||
"C3": 130, "CIS3": 139, "D3": 147, "DIS3": 155, "E3": 165, "F3": 174,
|
||||
"FIS3": 185, "G3": 196, "GIS3": 207, "A3": 220, "AIS3": 233, "H3": 247,
|
||||
"C4": 261, "CIS4": 277, "D4": 293, "DIS4": 311, "E4": 330, "F4": 349,
|
||||
"FIS4": 369, "G4": 392, "GIS4": 415, "A4": 440, "AIS4": 466, "H4": 494
|
||||
}
|
||||
# TONE:n for n-length
|
||||
# W to wait
|
||||
|
||||
ame2 = [
|
||||
"C2", "D2", "E2", "F2", "G2:2", "G2:2",
|
||||
"A2", "A2", "A2", "A2", "G2:2", "W",
|
||||
"A2", "A2", "A2", "A2", "G2:2", "W:2",
|
||||
"F2", "F2", "F2", "F2", "E2:2", "E2:2",
|
||||
"D2", "D2", "D2", "D2", "C2:2"
|
||||
]
|
||||
ame3 = [
|
||||
"C3", "D3", "E3", "F3", "G3:2", "G3:2",
|
||||
"A3", "A3", "A3", "A3", "G3:2", "W",
|
||||
"A3", "A3", "A3", "A3", "G3:2", "W:2",
|
||||
"F3", "F3", "F3", "F3", "E3:2", "E3:2",
|
||||
"D3", "D3", "D3", "D3", "C3:2"
|
||||
]
|
||||
ame4 = [
|
||||
"C4", "D4", "E4", "F4", "G4:2", "G4:2",
|
||||
"A4", "A4", "A4", "A4", "G4:2", "W",
|
||||
"A4", "A4", "A4", "A4", "G4:2", "W:2",
|
||||
"F4", "F4", "F4", "F4", "E4:2", "E4:2",
|
||||
"D4", "D4", "D4", "D4", "C4:2"
|
||||
]
|
||||
|
||||
|
||||
def play(pwm, pl):
|
||||
try:
|
||||
for k in pl:
|
||||
print(k)
|
||||
|
||||
ks = k.split(":")
|
||||
t = ks[0]
|
||||
d = 1
|
||||
if len(ks) > 1:
|
||||
d = int(ks[1])
|
||||
if not t == "W":
|
||||
f = tones[t]
|
||||
pwm.duty(DUTY)
|
||||
pwm.freq(f)
|
||||
for i in range(d):
|
||||
time.sleep(0.2)
|
||||
|
||||
pwm.duty(0)
|
||||
time.sleep(0.05)
|
||||
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
finally:
|
||||
pwm.duty(0)
|
||||
|
||||
def main():
|
||||
snd = machine.Pin(SND_PIN)
|
||||
pwm = machine.PWM(snd)
|
||||
|
||||
# play(pwm, ame2)
|
||||
# play(pwm, ame3)
|
||||
play(pwm, ame4)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue