Compare commits
No commits in common. "master" and "tannewt-patch-1" have entirely different histories.
master
...
tannewt-pa
|
|
@ -156,7 +156,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local
|
|||
# (useful for modules/projects where namespaces are manipulated during runtime
|
||||
# and thus existing member attributes cannot be deduced by static analysis. It
|
||||
# supports qualified module names, as well as Unix pattern matching.
|
||||
ignored-modules=board
|
||||
ignored-modules=
|
||||
|
||||
# Show a hint with possible names when a member name was not found. The aspect
|
||||
# of finding the hint is based on edit distance.
|
||||
|
|
|
|||
|
|
@ -16,17 +16,15 @@ deploy:
|
|||
provider: releases
|
||||
api_key: $GITHUB_TOKEN
|
||||
file_glob: true
|
||||
file: $TRAVIS_BUILD_DIR/bundles/*
|
||||
file: bundles/*
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
||||
|
||||
install:
|
||||
- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme
|
||||
- pip install --force-reinstall pylint==1.9.2
|
||||
- pip install pylint circuitpython-build-tools
|
||||
|
||||
script:
|
||||
- pylint adafruit_circuitplayground/*.py
|
||||
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py)
|
||||
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-circuitplayground --library_location .
|
||||
- cd docs && sphinx-build -E -W -b html . _build/html
|
||||
|
|
|
|||
|
|
@ -1,127 +1,74 @@
|
|||
# Adafruit Community Code of Conduct
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and leaders pledge to making participation in our project and
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level or type of
|
||||
experience, education, socio-economic status, nationality, personal appearance,
|
||||
race, religion, or sexual identity and orientation.
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
We are committed to providing a friendly, safe and welcoming environment for
|
||||
all.
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Be kind and courteous to others
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Collaborating with other community members
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and sexual attention or advances
|
||||
* The use of inappropriate images, including in a community member's avatar
|
||||
* The use of inappropriate language, including in a community member's nickname
|
||||
* Any spamming, flaming, baiting or other attention-stealing behavior
|
||||
* Excessive or unwelcome helping; answering outside the scope of the question
|
||||
asked
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate
|
||||
|
||||
The goal of the standards and moderation guidelines outlined here is to build
|
||||
and maintain a respectful community. We ask that you don’t just aim to be
|
||||
"technically unimpeachable", but rather try to be your best self.
|
||||
|
||||
We value many things beyond technical expertise, including collaboration and
|
||||
supporting others within our community. Providing a positive experience for
|
||||
other community members can have a much more significant impact than simply
|
||||
providing the correct answer.
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project leaders are responsible for clarifying the standards of acceptable
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project leaders have the right and responsibility to remove, edit, or
|
||||
reject messages, comments, commits, code, issues, and other contributions
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any community member for other behaviors that they deem
|
||||
inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Moderation
|
||||
|
||||
Instances of behaviors that violate the Adafruit Community Code of Conduct
|
||||
may be reported by any member of the community. Community members are
|
||||
encouraged to report these situations, including situations they witness
|
||||
involving other community members.
|
||||
|
||||
You may report in the following ways:
|
||||
|
||||
In any situation, you may send an email to <support@adafruit.com>.
|
||||
|
||||
On the Adafruit Discord, you may send an open message from any channel
|
||||
to all Community Helpers by tagging @community helpers. You may also send an
|
||||
open message from any channel, or a direct message to @kattni#1507,
|
||||
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
|
||||
@Andon#8175.
|
||||
|
||||
Email and direct message reports will be kept confidential.
|
||||
|
||||
In situations on Discord where the issue is particularly egregious, possibly
|
||||
illegal, requires immediate action, or violates the Discord terms of service,
|
||||
you should also report the message directly to Discord.
|
||||
|
||||
These are the steps for upholding our community’s standards of conduct.
|
||||
|
||||
1. Any member of the community may report any situation that violates the
|
||||
Adafruit Community Code of Conduct. All reports will be reviewed and
|
||||
investigated.
|
||||
2. If the behavior is an egregious violation, the community member who
|
||||
committed the violation may be banned immediately, without warning.
|
||||
3. Otherwise, moderators will first respond to such behavior with a warning.
|
||||
4. Moderators follow a soft "three strikes" policy - the community member may
|
||||
be given another chance, if they are receptive to the warning and change their
|
||||
behavior.
|
||||
5. If the community member is unreceptive or unreasonable when warned by a
|
||||
moderator, or the warning goes unheeded, they may be banned for a first or
|
||||
second offense. Repeated offenses will result in the community member being
|
||||
banned.
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct and the enforcement policies listed above apply to all
|
||||
Adafruit Community venues. This includes but is not limited to any community
|
||||
spaces (both public and private), the entire Adafruit Discord server, and
|
||||
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
|
||||
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
|
||||
interaction at a conference.
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. As a community
|
||||
member, you are representing our community, and are expected to behave
|
||||
accordingly.
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at support@adafruit.com. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 1.4, available at
|
||||
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
|
||||
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
For other projects adopting the Adafruit Community Code of
|
||||
Conduct, please contact the maintainers of those projects for enforcement.
|
||||
If you wish to use this code of conduct for your own project, consider
|
||||
explicitly mentioning your moderation policy or making a copy with your
|
||||
own moderation policy so as to avoid confusion.
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
|
|
|
|||
60
README.rst
|
|
@ -6,17 +6,17 @@ Introduction
|
|||
:target: https://circuitpython.readthedocs.io/projects/circuitplayground/en/latest/
|
||||
:alt: Documentation Status
|
||||
|
||||
.. image :: https://badges.gitter.im/adafruit/circuitpython.svg
|
||||
:target: https://gitter.im/adafruit/circuitpython?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
|
||||
:alt: Gitter
|
||||
|
||||
.. image :: https://img.shields.io/discord/327254708534116352.svg
|
||||
:target: https://adafru.it/discord
|
||||
:alt: Discord
|
||||
|
||||
.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.svg?branch=master
|
||||
:target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_CircuitPlayground
|
||||
:alt: Build Status
|
||||
|
||||
This high level library provides objects that represent CircuitPlayground hardware.
|
||||
|
||||
.. image :: ../docs/_static/circuitplayground_express.jpg
|
||||
.. image :: /_static/circuitplayground_express.jpg
|
||||
:target: https://adafruit.com/product/3333
|
||||
:alt: CircuitPlayground Express
|
||||
|
||||
|
|
@ -46,50 +46,10 @@ Contributions are welcome! Please read our `Code of Conduct
|
|||
<https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/blob/master/CODE_OF_CONDUCT.md>`_
|
||||
before contributing to help this project stay welcoming.
|
||||
|
||||
Building locally
|
||||
================
|
||||
API Reference
|
||||
=============
|
||||
|
||||
To build this library locally you'll need to install the
|
||||
`circuitpython-build-tools <https://github.com/adafruit/circuitpython-build-tools>`_ package.
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
python3 -m venv .env
|
||||
source .env/bin/activate
|
||||
pip install circuitpython-build-tools
|
||||
|
||||
Once installed, make sure you are in the virtual environment:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
source .env/bin/activate
|
||||
|
||||
Then run the build:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-circuitplayground --library_location .
|
||||
|
||||
Sphinx documentation
|
||||
-----------------------
|
||||
|
||||
Sphinx is used to build the documentation based on rST files and comments in the code. First,
|
||||
install dependencies (feel free to reuse the virtual environment from above):
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
python3 -m venv .env
|
||||
source .env/bin/activate
|
||||
pip install Sphinx sphinx-rtd-theme
|
||||
|
||||
Now, once you have the virtual environment activated:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
cd docs
|
||||
sphinx-build -E -W -b html . _build/html
|
||||
|
||||
This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
|
||||
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
|
||||
locally verify it will pass.
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
adafruit_circuitplayground/index
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 692 KiB After Width: | Height: | Size: 692 KiB |
|
Before Width: | Height: | Size: 361 KiB After Width: | Height: | Size: 361 KiB |
|
Before Width: | Height: | Size: 362 KiB After Width: | Height: | Size: 362 KiB |
|
Before Width: | Height: | Size: 698 KiB After Width: | Height: | Size: 698 KiB |
|
Before Width: | Height: | Size: 698 KiB After Width: | Height: | Size: 698 KiB |
|
Before Width: | Height: | Size: 698 KiB After Width: | Height: | Size: 698 KiB |
|
Before Width: | Height: | Size: 698 KiB After Width: | Height: | Size: 698 KiB |
|
Before Width: | Height: | Size: 697 KiB After Width: | Height: | Size: 697 KiB |
|
Before Width: | Height: | Size: 698 KiB After Width: | Height: | Size: 698 KiB |
|
Before Width: | Height: | Size: 698 KiB After Width: | Height: | Size: 698 KiB |
|
Before Width: | Height: | Size: 742 KiB After Width: | Height: | Size: 742 KiB |
|
Before Width: | Height: | Size: 351 KiB After Width: | Height: | Size: 351 KiB |
|
Before Width: | Height: | Size: 361 KiB After Width: | Height: | Size: 361 KiB |
|
Before Width: | Height: | Size: 361 KiB After Width: | Height: | Size: 361 KiB |
|
Before Width: | Height: | Size: 361 KiB After Width: | Height: | Size: 361 KiB |
|
Before Width: | Height: | Size: 361 KiB After Width: | Height: | Size: 361 KiB |
|
Before Width: | Height: | Size: 692 KiB After Width: | Height: | Size: 692 KiB |
|
Before Width: | Height: | Size: 362 KiB After Width: | Height: | Size: 362 KiB |
0
adafruit_circuitplayground/__init__.py
Normal file
|
|
@ -1,7 +1,7 @@
|
|||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
|
||||
# Copyright (c) 2017-2018 Kattni Rembor for Adafruit Industries
|
||||
# Copyright (c) 2017 Kattni Rembor for Adafruit Industries
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
# We have a lot of attributes for this complex library.
|
||||
# We have a lot of attributes for this complex sensor.
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
|
||||
"""
|
||||
|
|
@ -38,23 +38,12 @@ import math
|
|||
import sys
|
||||
import time
|
||||
# pylint: disable=wrong-import-position
|
||||
try:
|
||||
lib_index = sys.path.index("/lib") # pylint: disable=invalid-name
|
||||
if lib_index < sys.path.index(".frozen"):
|
||||
# Prefer frozen modules over those in /lib.
|
||||
sys.path.insert(lib_index, ".frozen")
|
||||
except ValueError:
|
||||
# Don't change sys.path if it doesn't contain "lib" or ".frozen".
|
||||
pass
|
||||
sys.path.insert(0, ".frozen") # prefer frozen modules over local
|
||||
|
||||
import adafruit_lis3dh
|
||||
import adafruit_thermistor
|
||||
import analogio
|
||||
import audioio
|
||||
try:
|
||||
import audiocore
|
||||
except ImportError:
|
||||
audiocore = audioio
|
||||
import board
|
||||
import busio
|
||||
import digitalio
|
||||
|
|
@ -109,111 +98,64 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
self._speaker_enable.switch_to_output(value=False)
|
||||
self._sample = None
|
||||
self._sine_wave = None
|
||||
self._sine_wave_sample = None
|
||||
|
||||
# Define touch:
|
||||
# Initially, self._touches stores the pin used for a particular touch. When that touch is
|
||||
# used for the first time, the pin is replaced with the corresponding TouchIn object.
|
||||
# This saves a little RAM over using a separate read-only pin tuple.
|
||||
# For example, after `cpx.touch_A2`, self._touches is equivalent to:
|
||||
# [None, board.A1, touchio.TouchIn(board.A2), board.A3, ...]
|
||||
# Slot 0 is not used (A0 is not allowed as a touch pin).
|
||||
self._touches = [None, board.A1, board.A2, board.A3, board.A4, board.A5, board.A6, board.A7]
|
||||
# We chose these verbose touch_A# names so that beginners could use it without understanding
|
||||
# lists and the capital A to match the pin name. The capitalization is not strictly Python
|
||||
# style, so everywhere we use these names, we whitelist the errors using:
|
||||
# pylint: disable=invalid-name
|
||||
self._touch_A1 = None
|
||||
self._touch_A2 = None
|
||||
self._touch_A3 = None
|
||||
self._touch_A4 = None
|
||||
self._touch_A5 = None
|
||||
self._touch_A6 = None
|
||||
self._touch_A7 = None
|
||||
self._touch_threshold_adjustment = 0
|
||||
|
||||
# Define acceleration:
|
||||
self._i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
|
||||
self._int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
|
||||
self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19, int1=self._int1)
|
||||
self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19)
|
||||
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G
|
||||
|
||||
# Initialise tap:
|
||||
self._detect_taps = 1
|
||||
self.detect_taps = 1
|
||||
try:
|
||||
self._lis3dh.set_tap(2, 18, time_limit=4, time_latency=17, time_window=110)
|
||||
except AttributeError:
|
||||
pass
|
||||
self._last_tap = False
|
||||
|
||||
@property
|
||||
def detect_taps(self):
|
||||
"""Configure what type of tap is detected by ``cpx.tapped``. Use ``1`` for single-tap
|
||||
detection and ``2`` for double-tap detection. This does nothing without ``cpx.tapped``.
|
||||
def double_tap(self):
|
||||
"""True once after a double tap.
|
||||
|
||||
.. image :: ../docs/_static/accelerometer.jpg
|
||||
.. image :: /_static/accelerometer.jpg
|
||||
:alt: Accelerometer
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.detect_taps = 1
|
||||
while True:
|
||||
if cpx.tapped:
|
||||
print("Single tap detected!")
|
||||
"""
|
||||
return self._detect_taps
|
||||
|
||||
@detect_taps.setter
|
||||
def detect_taps(self, value):
|
||||
self._detect_taps = value
|
||||
if value == 1:
|
||||
self._lis3dh.set_tap(value, 90, time_limit=4, time_latency=50, time_window=255)
|
||||
if value == 2:
|
||||
self._lis3dh.set_tap(value, 60, time_limit=10, time_latency=50, time_window=255)
|
||||
|
||||
@property
|
||||
def tapped(self):
|
||||
"""True once after a detecting a tap. Requires ``cpx.detect_taps``.
|
||||
|
||||
.. image :: ../docs/_static/accelerometer.jpg
|
||||
:alt: Accelerometer
|
||||
|
||||
Tap the CPX once for a single-tap, or quickly tap twice for a double-tap.
|
||||
Quickly tap the CPX twice to double-tap.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.detect_taps = 1
|
||||
|
||||
while True:
|
||||
if cpx.tapped:
|
||||
print("Single tap detected!")
|
||||
|
||||
To use single and double tap together, you must have a delay between them. It
|
||||
will not function properly without it. This example uses both by counting a
|
||||
specified number of each type of tap before moving on in the code.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
# Set to check for single-taps.
|
||||
cpx.detect_taps = 1
|
||||
tap_count = 0
|
||||
|
||||
# We're looking for 2 single-taps before moving on.
|
||||
while tap_count < 2:
|
||||
if cpx.tapped:
|
||||
tap_count += 1
|
||||
print("Reached 2 single-taps!")
|
||||
|
||||
# Now switch to checking for double-taps
|
||||
tap_count = 0
|
||||
cpx.detect_taps = 2
|
||||
|
||||
# We're looking for 2 double-taps before moving on.
|
||||
while tap_count < 2:
|
||||
if cpx.tapped:
|
||||
tap_count += 1
|
||||
print("Reached 2 double-taps!")
|
||||
print("Done.")
|
||||
|
||||
if cpx.double_tap:
|
||||
print("Double tap!")
|
||||
"""
|
||||
return self._lis3dh.tapped
|
||||
try:
|
||||
tapped = self._lis3dh.tapped
|
||||
first_double_tap = tapped and not self._last_tap
|
||||
self._last_tap = tapped
|
||||
return first_double_tap
|
||||
except AttributeError:
|
||||
raise RuntimeError("Oops! You need a newer version of CircuitPython "
|
||||
"(2.2.0 or greater) to use this feature.")
|
||||
|
||||
@property
|
||||
def acceleration(self):
|
||||
"""Obtain data from the x, y and z axes.
|
||||
|
||||
.. image :: ../docs/_static/accelerometer.jpg
|
||||
.. image :: /_static/accelerometer.jpg
|
||||
:alt: Accelerometer
|
||||
|
||||
This example prints the values. Try moving the board to see how the
|
||||
|
|
@ -234,7 +176,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
|
||||
:param int shake_threshold: The threshold shake must exceed to return true (Default: 30)
|
||||
|
||||
.. image :: ../docs/_static/accelerometer.jpg
|
||||
.. image :: /_static/accelerometer.jpg
|
||||
:alt: Accelerometer
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -259,24 +201,17 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
if cpx.shake(shake_threshold=20):
|
||||
print("Shake detected more easily than before!")
|
||||
"""
|
||||
return self._lis3dh.shake(shake_threshold=shake_threshold)
|
||||
try:
|
||||
return self._lis3dh.shake(shake_threshold=shake_threshold)
|
||||
except AttributeError:
|
||||
raise RuntimeError("Oops! You need a newer version of CircuitPython "
|
||||
"(2.2.0 or greater) to use this feature.")
|
||||
|
||||
def _touch(self, i):
|
||||
if not isinstance(self._touches[i], touchio.TouchIn):
|
||||
# First time referenced. Get the pin from the slot for this touch
|
||||
# and replace it with a TouchIn object for the pin.
|
||||
self._touches[i] = touchio.TouchIn(self._touches[i])
|
||||
self._touches[i].threshold += self._touch_threshold_adjustment
|
||||
return self._touches[i].value
|
||||
|
||||
# We chose these verbose touch_A# names so that beginners could use it without understanding
|
||||
# lists and the capital A to match the pin name. The capitalization is not strictly Python
|
||||
# style, so everywhere we use these names, we whitelist the errors using:
|
||||
@property
|
||||
def touch_A1(self): # pylint: disable=invalid-name
|
||||
"""Detect touch on capacitive touch pad A1.
|
||||
|
||||
.. image :: ../docs/_static/capacitive_touch_pad_A1.jpg
|
||||
.. image :: /_static/capacitive_touch_pad_A1.jpg
|
||||
:alt: Capacitive touch pad A1
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -287,13 +222,16 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
if cpx.touch_A1:
|
||||
print('Touched pad A1')
|
||||
"""
|
||||
return self._touch(1)
|
||||
if self._touch_A1 is None:
|
||||
self._touch_A1 = touchio.TouchIn(board.A1)
|
||||
self._touch_A1.threshold += self._touch_threshold_adjustment
|
||||
return self._touch_A1.value
|
||||
|
||||
@property
|
||||
def touch_A2(self): # pylint: disable=invalid-name
|
||||
"""Detect touch on capacitive touch pad A2.
|
||||
|
||||
.. image :: ../docs/_static/capacitive_touch_pad_A2.jpg
|
||||
.. image :: /_static/capacitive_touch_pad_A2.jpg
|
||||
:alt: Capacitive touch pad A2
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -304,13 +242,16 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
if cpx.touch_A2:
|
||||
print('Touched pad A2')
|
||||
"""
|
||||
return self._touch(2)
|
||||
if self._touch_A2 is None:
|
||||
self._touch_A2 = touchio.TouchIn(board.A2)
|
||||
self._touch_A2.threshold += self._touch_threshold_adjustment
|
||||
return self._touch_A2.value
|
||||
|
||||
@property
|
||||
def touch_A3(self): # pylint: disable=invalid-name
|
||||
"""Detect touch on capacitive touch pad A3.
|
||||
|
||||
.. image :: ../docs/_static/capacitive_touch_pad_A3.jpg
|
||||
.. image :: /_static/capacitive_touch_pad_A3.jpg
|
||||
:alt: Capacitive touch pad A3
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -321,13 +262,16 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
if cpx.touch_A3:
|
||||
print('Touched pad A3')
|
||||
"""
|
||||
return self._touch(3)
|
||||
if self._touch_A3 is None:
|
||||
self._touch_A3 = touchio.TouchIn(board.A3)
|
||||
self._touch_A3.threshold += self._touch_threshold_adjustment
|
||||
return self._touch_A3.value
|
||||
|
||||
@property
|
||||
def touch_A4(self): # pylint: disable=invalid-name
|
||||
"""Detect touch on capacitive touch pad A4.
|
||||
|
||||
.. image :: ../docs/_static/capacitive_touch_pad_A4.jpg
|
||||
.. image :: /_static/capacitive_touch_pad_A4.jpg
|
||||
:alt: Capacitive touch pad A4
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -338,13 +282,16 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
if cpx.touch_A4:
|
||||
print('Touched pad A4')
|
||||
"""
|
||||
return self._touch(4)
|
||||
if self._touch_A4 is None:
|
||||
self._touch_A4 = touchio.TouchIn(board.A4)
|
||||
self._touch_A4.threshold += self._touch_threshold_adjustment
|
||||
return self._touch_A4.value
|
||||
|
||||
@property
|
||||
def touch_A5(self): # pylint: disable=invalid-name
|
||||
"""Detect touch on capacitive touch pad A5.
|
||||
|
||||
.. image :: ../docs/_static/capacitive_touch_pad_A5.jpg
|
||||
.. image :: /_static/capacitive_touch_pad_A5.jpg
|
||||
:alt: Capacitive touch pad A5
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -355,13 +302,16 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
if cpx.touch_A5:
|
||||
print('Touched pad A5')
|
||||
"""
|
||||
return self._touch(5)
|
||||
if self._touch_A5 is None:
|
||||
self._touch_A5 = touchio.TouchIn(board.A5)
|
||||
self._touch_A5.threshold += self._touch_threshold_adjustment
|
||||
return self._touch_A5.value
|
||||
|
||||
@property
|
||||
def touch_A6(self): # pylint: disable=invalid-name
|
||||
"""Detect touch on capacitive touch pad A6.
|
||||
|
||||
.. image :: ../docs/_static/capacitive_touch_pad_A6.jpg
|
||||
.. image :: /_static/capacitive_touch_pad_A6.jpg
|
||||
:alt: Capacitive touch pad A6
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -372,13 +322,16 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
if cpx.touch_A6:
|
||||
print('Touched pad A6')
|
||||
"""
|
||||
return self._touch(6)
|
||||
if self._touch_A6 is None:
|
||||
self._touch_A6 = touchio.TouchIn(board.A6)
|
||||
self._touch_A6.threshold += self._touch_threshold_adjustment
|
||||
return self._touch_A6.value
|
||||
|
||||
@property
|
||||
def touch_A7(self): # pylint: disable=invalid-name
|
||||
"""Detect touch on capacitive touch pad A7.
|
||||
|
||||
.. image :: ../docs/_static/capacitive_touch_pad_A7.jpg
|
||||
.. image :: /_static/capacitive_touch_pad_A7.jpg
|
||||
:alt: Capacitive touch pad A7
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -389,7 +342,10 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
if cpx.touch_A7:
|
||||
print('Touched pad A7')
|
||||
"""
|
||||
return self._touch(7)
|
||||
if self._touch_A7 is None:
|
||||
self._touch_A7 = touchio.TouchIn(board.A7)
|
||||
self._touch_A7.threshold += self._touch_threshold_adjustment
|
||||
return self._touch_A7.value
|
||||
|
||||
def adjust_touch_threshold(self, adjustment):
|
||||
"""Adjust the threshold needed to activate the capacitive touch pads.
|
||||
|
|
@ -397,7 +353,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
|
||||
:param int adjustment: The desired threshold increase
|
||||
|
||||
.. image :: ../docs/_static/capacitive_touch_pads.jpg
|
||||
.. image :: /_static/capacitive_touch_pads.jpg
|
||||
:alt: Capacitive touch pads
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -410,14 +366,15 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
if cpx.touch_A1:
|
||||
print('Touched pad A1')
|
||||
"""
|
||||
for touch_in in self._touches:
|
||||
if isinstance(touch_in, touchio.TouchIn):
|
||||
for pad_name in ["_touch_A" + str(x) for x in range(1, 8)]:
|
||||
touch_in = getattr(self, pad_name)
|
||||
if touch_in:
|
||||
touch_in.threshold += adjustment
|
||||
self._touch_threshold_adjustment += adjustment
|
||||
|
||||
@property
|
||||
def pixels(self):
|
||||
"""Sequence-like object representing the ten NeoPixels around the outside
|
||||
"""Sequence like object representing the ten NeoPixels around the outside
|
||||
of the CircuitPlayground. Each pixel is at a certain index in the sequence
|
||||
as labeled below. Colors can be RGB hex like 0x110000 for red where each
|
||||
two digits are a color (0xRRGGBB) or a tuple like (17, 0, 0) where (R, G, B).
|
||||
|
|
@ -426,7 +383,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
|
||||
See `neopixel.NeoPixel` for more info.
|
||||
|
||||
.. image :: ../docs/_static/neopixel_numbering.jpg
|
||||
.. image :: /_static/neopixel_numbering.jpg
|
||||
:alt: NeoPixel order diagram
|
||||
|
||||
Here is an example that sets the first pixel green and the second red.
|
||||
|
|
@ -449,7 +406,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
def button_a(self):
|
||||
"""``True`` when Button A is pressed. ``False`` if not.
|
||||
|
||||
.. image :: ../docs/_static/button_a.jpg
|
||||
.. image :: /_static/button_a.jpg
|
||||
:alt: Button A
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -466,7 +423,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
def button_b(self):
|
||||
"""``True`` when Button B is pressed. ``False`` if not.
|
||||
|
||||
.. image :: ../docs/_static/button_b.jpg
|
||||
.. image :: /_static/button_b.jpg
|
||||
:alt: Button B
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -485,7 +442,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
``True`` when the switch is to the left next to the music notes.
|
||||
``False`` when it is to the right towards the ear.
|
||||
|
||||
.. image :: ../docs/_static/slide_switch.jpg
|
||||
.. image :: ../_static/slide_switch.jpg
|
||||
:alt: Slide switch
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -503,7 +460,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
def temperature(self):
|
||||
"""The temperature of the CircuitPlayground in Celsius.
|
||||
|
||||
.. image :: ../docs/_static/thermistor.jpg
|
||||
.. image :: /_static/thermistor.jpg
|
||||
:alt: Temperature sensor
|
||||
|
||||
Converting this to Farenheit is easy!
|
||||
|
|
@ -526,7 +483,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
def light(self):
|
||||
"""The brightness of the CircuitPlayground in approximate Lux.
|
||||
|
||||
.. image :: ../docs/_static/light_sensor.jpg
|
||||
.. image :: /_static/light_sensor.jpg
|
||||
:alt: Light sensor
|
||||
|
||||
Try covering the sensor next to the eye to see it change.
|
||||
|
|
@ -546,7 +503,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
def red_led(self):
|
||||
"""The red led next to the USB plug marked D13.
|
||||
|
||||
.. image :: ../docs/_static/red_led.jpg
|
||||
.. image :: /_static/red_led.jpg
|
||||
:alt: D13 LED
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -573,16 +530,12 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
for i in range(length):
|
||||
yield int(tone_volume * math.sin(2*math.pi*(i / length)) + shift)
|
||||
|
||||
def _generate_sample(self, length=100):
|
||||
def _generate_sample(self):
|
||||
if self._sample is not None:
|
||||
return
|
||||
length = 100
|
||||
self._sine_wave = array.array("H", Express._sine_sample(length))
|
||||
if sys.implementation.version[0] >= 3:
|
||||
self._sample = audioio.AudioOut(board.SPEAKER)
|
||||
self._sine_wave_sample = audiocore.RawSample(self._sine_wave)
|
||||
else:
|
||||
raise NotImplementedError("Please use CircuitPython 3.0 or higher.")
|
||||
|
||||
self._sample = audioio.AudioOut(board.SPEAKER, self._sine_wave)
|
||||
|
||||
def play_tone(self, frequency, duration):
|
||||
""" Produce a tone using the speaker. Try changing frequency to change
|
||||
|
|
@ -591,7 +544,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
:param int frequency: The frequency of the tone in Hz
|
||||
:param float duration: The duration of the tone in seconds
|
||||
|
||||
.. image :: ../docs/_static/speaker.jpg
|
||||
.. image :: /_static/speaker.jpg
|
||||
:alt: Onboard speaker
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -611,7 +564,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
|
||||
:param int frequency: The frequency of the tone in Hz
|
||||
|
||||
.. image :: ../docs/_static/speaker.jpg
|
||||
.. image :: /_static/speaker.jpg
|
||||
:alt: Onboard speaker
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -627,22 +580,16 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
cpx.stop_tone()
|
||||
"""
|
||||
self._speaker_enable.value = True
|
||||
length = 100
|
||||
if length * frequency > 350000:
|
||||
length = 350000 // frequency
|
||||
self._generate_sample(length)
|
||||
self._generate_sample()
|
||||
# Start playing a tone of the specified frequency (hz).
|
||||
if sys.implementation.version[0] >= 3:
|
||||
self._sine_wave_sample.sample_rate = int(len(self._sine_wave) * frequency)
|
||||
if not self._sample.playing:
|
||||
self._sample.play(self._sine_wave_sample, loop=True)
|
||||
else:
|
||||
raise NotImplementedError("Please use CircuitPython 3.0 or higher.")
|
||||
self._sample.frequency = int(len(self._sine_wave) * frequency)
|
||||
if not self._sample.playing:
|
||||
self._sample.play(loop=True)
|
||||
|
||||
def stop_tone(self):
|
||||
""" Use with start_tone to stop the tone produced.
|
||||
|
||||
.. image :: ../docs/_static/speaker.jpg
|
||||
.. image :: /_static/speaker.jpg
|
||||
:alt: Onboard speaker
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -660,8 +607,6 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
# Stop playing any tones.
|
||||
if self._sample is not None and self._sample.playing:
|
||||
self._sample.stop()
|
||||
self._sample.deinit()
|
||||
self._sample = None
|
||||
self._speaker_enable.value = False
|
||||
|
||||
def play_file(self, file_name):
|
||||
|
|
@ -669,7 +614,7 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
|
||||
:param file_name: The name of your .wav file in quotation marks including .wav
|
||||
|
||||
.. image :: ../docs/_static/speaker.jpg
|
||||
.. image :: /_static/speaker.jpg
|
||||
:alt: Onboard speaker
|
||||
|
||||
.. code-block:: python
|
||||
|
|
@ -683,16 +628,12 @@ class Express: # pylint: disable=too-many-public-methods
|
|||
cpx.play_file("rimshot.wav")
|
||||
"""
|
||||
# Play a specified file.
|
||||
self.stop_tone()
|
||||
self._speaker_enable.value = True
|
||||
if sys.implementation.version[0] >= 3:
|
||||
with audioio.AudioOut(board.SPEAKER) as audio:
|
||||
wavefile = audiocore.WaveFile(open(file_name, "rb"))
|
||||
audio.play(wavefile)
|
||||
while audio.playing:
|
||||
pass
|
||||
else:
|
||||
raise NotImplementedError("Please use CircuitPython 3.0 or higher.")
|
||||
audio = audioio.AudioOut(board.SPEAKER, open(file_name, "rb"))
|
||||
|
||||
audio.play()
|
||||
while audio.playing:
|
||||
pass
|
||||
self._speaker_enable.value = False
|
||||
|
||||
|
||||
|
|
|
|||
9
adafruit_circuitplayground/index.rst
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
CircuitPlayground APIs
|
||||
===========================================
|
||||
|
||||
`express` - CircuitPlayground Express (CPX for short)
|
||||
-----------------------------------------------------
|
||||
|
||||
.. automodule:: adafruit_circuitplayground.express
|
||||
:members:
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ templates_path = ['_templates']
|
|||
source_suffix = '.rst'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
master_doc = 'README'
|
||||
|
||||
# General information about the project.
|
||||
project = u'Adafruit CircuitPlayground Library'
|
||||
|
|
@ -54,7 +54,7 @@ language = None
|
|||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This patterns also effect to html_static_path and html_extra_path
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
|
|
@ -71,9 +71,6 @@ pygments_style = 'sphinx'
|
|||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
||||
todo_include_todos = False
|
||||
|
||||
# If this is True, todo emits a warning for each TODO entries. The default is False.
|
||||
todo_emit_warnings = True
|
||||
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
|
|
@ -98,12 +95,6 @@ else:
|
|||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# The name of an image file (relative to this directory) to use as a favicon of
|
||||
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#
|
||||
html_favicon = '_static/favicon.ico'
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'AdafruitCircuitPlaygroundLibrarydoc'
|
||||
|
||||
BIN
docs/_static/favicon.ico
vendored
|
Before Width: | Height: | Size: 4.3 KiB |
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
.. If you created a package, create one automodule per module in the package.
|
||||
|
||||
.. automodule:: adafruit_circuitplayground.express
|
||||
:members:
|
||||
|
|
@ -1,144 +0,0 @@
|
|||
Simple test
|
||||
------------
|
||||
|
||||
Ensure your device works with this simple test.
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_acceleration.py
|
||||
:caption: examples/circuitplayground_acceleration.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_pixels_simpletest.py
|
||||
:caption: examples/circuitplayground_pixels_simpletest.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_shake.py
|
||||
:caption: examples/circuitplayground_shake.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_tapdetect_single_double.py
|
||||
:caption: examples/circuitplayground_tapdetect_single_double.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_tapdetect.py
|
||||
:caption: examples/circuitplayground_tapdetect.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_tone.py
|
||||
:caption: examples/circuitplayground_tone.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_touched.py
|
||||
:caption: examples/circuitplayground_touched.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_acceleration_neopixels.py
|
||||
:caption: examples/circuitplayground_acceleration_neopixels.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_button_a.py
|
||||
:caption: examples/circuitplayground_button_a.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_button_b.py
|
||||
:caption: examples/circuitplayground_button_b.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_buttons_1_neopixel.py
|
||||
:caption: examples/circuitplayground_buttons_1_neopixel.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_buttons_neopixels.py
|
||||
:caption: examples/circuitplayground_buttons_neopixels.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_ir_receive.py
|
||||
:caption: examples/circuitplayground_ir_receive.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_ir_transmit.py
|
||||
:caption: examples/circuitplayground_ir_transmit.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_light_neopixels.py
|
||||
:caption: examples/circuitplayground_light_neopixels.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_light.py
|
||||
:caption: examples/circuitplayground_light.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_neopixel_0_1.py
|
||||
:caption: examples/circuitplayground_neopixel_0_1.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_light_plotter.py
|
||||
:caption: examples/circuitplayground_light_plotter.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_play_file_buttons.py
|
||||
:caption: examples/circuitplayground_play_file_buttons.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_play_file.py
|
||||
:caption: examples/circuitplayground_play_file.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_play_tone_buttons.py
|
||||
:caption: examples/circuitplayground_play_tone_buttons.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_play_tone.py
|
||||
:caption: examples/circuitplayground_play_tone.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_red_led_blinky.py
|
||||
:caption: examples/circuitplayground_red_led_blinky.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_red_led_blnky_short.py
|
||||
:caption: examples/circuitplayground_red_led_blnky_short.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_red_led.py
|
||||
:caption: examples/circuitplayground_red_led.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_slide_switch_red_led.py
|
||||
:caption: examples/circuitplayground_slide_switch_red_led.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_slide_switch_red_led_short.py
|
||||
:caption: examples/circuitplayground_slide_switch_red_led_short.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_slide_switch.py
|
||||
:caption: examples/circuitplayground_slide_switch.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_sound_meter.py
|
||||
:caption: examples/circuitplayground_sound_meter.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_tap_red_led.py
|
||||
:caption: examples/circuitplayground_tap_red_led.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_temperature_neopixels.py
|
||||
:caption: examples/circuitplayground_temperature_neopixels.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_temperture_plotter.py
|
||||
:caption: examples/circuitplayground_temperture_plotter.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_temperture.py
|
||||
:caption: examples/circuitplayground_temperture.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_touch_pixel_fill_rainbow.py
|
||||
:caption: examples/circuitplayground_touch_pixel_fill_rainbow.py
|
||||
:linenos:
|
||||
|
||||
.. literalinclude:: ../examples/circuitplayground_touch_pixel_rainbow.py
|
||||
:caption: examples/circuitplayground_touch_pixel_rainbow.py
|
||||
:linenos:
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
.. include:: ../README.rst
|
||||
|
||||
Table of Contents
|
||||
=================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 4
|
||||
:hidden:
|
||||
|
||||
self
|
||||
|
||||
.. toctree::
|
||||
:caption: Examples
|
||||
|
||||
examples
|
||||
|
||||
.. toctree::
|
||||
:caption: API Reference
|
||||
:maxdepth: 3
|
||||
|
||||
api
|
||||
|
||||
.. toctree::
|
||||
:caption: Tutorials
|
||||
|
||||
.. toctree::
|
||||
:caption: Related Products
|
||||
|
||||
Adafruit CircuitPlayground Express <https://www.adafruit.com/product/3333>
|
||||
|
||||
.. toctree::
|
||||
:caption: Other Links
|
||||
|
||||
Download <https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/releases/latest>
|
||||
CircuitPython Reference Documentation <https://circuitpython.readthedocs.io>
|
||||
CircuitPython Support Forum <https://forums.adafruit.com/viewforum.php?f=60>
|
||||
Discord Chat <https://adafru.it/discord>
|
||||
Adafruit Learning System <https://learn.adafruit.com>
|
||||
Adafruit Blog <https://blog.adafruit.com>
|
||||
Adafruit Store <https://www.adafruit.com>
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
x, y, z = cpx.acceleration
|
||||
print(x, y, z)
|
||||
|
||||
time.sleep(0.1)
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
"""Maps acceleration (tilt) to Neopixel colors.
|
||||
|
||||
x, y, and z acceleration components map to red, green and blue,
|
||||
respectively.
|
||||
|
||||
When the CPX is level, the lights are blue because there is no acceleration
|
||||
on x or y, but on z, gravity pulls at 9.81 meters per second per second (m/s²).
|
||||
When banking, the vertical (z) axis is no longer directly aligned with gravity,
|
||||
so the blue decreases, and red increases because gravity is now pulling more
|
||||
along the x axis. Similarly, when changing the pitch from level, we see blue change
|
||||
to green.
|
||||
|
||||
This video walks you through the code: https://youtu.be/eNpPLbYx-iA
|
||||
"""
|
||||
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.pixels.brightness = 0.2 # Adjust overall brightness as desired, between 0 and 1
|
||||
|
||||
|
||||
def color_amount(accel_component):
|
||||
"""Convert acceleration component (x, y, or z) to color amount (r, g, or b)"""
|
||||
standard_gravity = 9.81 # Acceleration (m/s²) due to gravity at the earth’s surface
|
||||
accel_magnitude = abs(accel_component) # Ignore the direction
|
||||
constrained_accel = min(accel_magnitude, standard_gravity) # Constrain values
|
||||
normalized_accel = constrained_accel / standard_gravity # Convert to 0–1
|
||||
return round(normalized_accel * 255) # Convert to 0–255
|
||||
|
||||
|
||||
def format_acceleration():
|
||||
return ', '.join(('{:>6.2f}'.format(axis_value) for axis_value in acceleration))
|
||||
|
||||
|
||||
def format_rgb():
|
||||
return ', '.join(('{:>3d}'.format(rgb_amount) for rgb_amount in rgb_amounts))
|
||||
|
||||
|
||||
def log_values():
|
||||
print('({}) ==> ({})'.format(format_acceleration(), format_rgb()))
|
||||
|
||||
|
||||
while True:
|
||||
acceleration = cpx.acceleration
|
||||
rgb_amounts = [color_amount(axis_value) for axis_value in acceleration]
|
||||
cpx.pixels.fill(rgb_amounts)
|
||||
log_values()
|
||||
time.sleep(0.1)
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
"""If the switch is to the right, it will appear that nothing is happening. Move the switch to the
|
||||
left to see the NeoPixels light up in colors related to the accelerometer! The CPX has an
|
||||
accelerometer in the center that returns (x, y, z) acceleration values. This program uses those
|
||||
values to light up the NeoPixels based on those acceleration values."""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
# Main loop gets x, y and z axis acceleration, prints the values, and turns on
|
||||
# red, green and blue, at levels related to the x, y and z values.
|
||||
while True:
|
||||
if not cpx.switch:
|
||||
# If the switch is to the right, it returns False!
|
||||
print("Slide switch off!")
|
||||
cpx.pixels.fill((0, 0, 0))
|
||||
continue
|
||||
else:
|
||||
R = 0
|
||||
G = 0
|
||||
B = 0
|
||||
x, y, z = cpx.acceleration
|
||||
print((x, y, z))
|
||||
cpx.pixels.fill(((R + abs(int(x))), (G + abs(int(y))), (B + abs(int(z)))))
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
"""This example turns on the little red LED when button A is pressed."""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
if cpx.button_a:
|
||||
print("Button A pressed!")
|
||||
cpx.red_led = True
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
"""This example turns the little red LED on only while button B is currently being pressed."""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
# This code is written to be readable versus being Pylint compliant.
|
||||
# pylint: disable=simplifiable-if-statement
|
||||
|
||||
while True:
|
||||
if cpx.button_b:
|
||||
cpx.red_led = True
|
||||
else:
|
||||
cpx.red_led = False
|
||||
|
||||
# Can also be written as:
|
||||
# cpx.red_led = cpx.button_b
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
"""This example lights up the third NeoPixel while button A is being pressed, and lights up the
|
||||
eighth NeoPixel while button B is being pressed."""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.pixels.brightness = 0.3
|
||||
cpx.pixels.fill((0, 0, 0)) # Turn off the NeoPixels if they're on!
|
||||
|
||||
while True:
|
||||
if cpx.button_a:
|
||||
cpx.pixels[2] = (0, 255, 0)
|
||||
else:
|
||||
cpx.pixels[2] = (0, 0, 0)
|
||||
|
||||
if cpx.button_b:
|
||||
cpx.pixels[7] = (0, 0, 255)
|
||||
else:
|
||||
cpx.pixels[7] = (0, 0, 0)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
"""This example lights up half the NeoPixels red while button A is being pressed, and half the
|
||||
NeoPixels green while button B is being pressed."""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.pixels.brightness = 0.3
|
||||
cpx.pixels.fill((0, 0, 0)) # Turn off the NeoPixels if they're on!
|
||||
|
||||
while True:
|
||||
if cpx.button_a:
|
||||
cpx.pixels[0:5] = [(255, 0, 0)] * 5
|
||||
else:
|
||||
cpx.pixels[0:5] = [(0, 0, 0)] * 5
|
||||
|
||||
if cpx.button_b:
|
||||
cpx.pixels[5:10] = [(0, 255, 0)] * 5
|
||||
else:
|
||||
cpx.pixels[5:10] = [(0, 0, 0)] * 5
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
"""THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE.
|
||||
This example requires the adafruit_irremote.mpy library.
|
||||
|
||||
This example uses the IR receiver found near the center of the board. Works with another CPX
|
||||
running the cpx_ir_transmit.py example. The NeoPixels will light up when the buttons on the
|
||||
TRANSMITTING CPX are pressed!"""
|
||||
import pulseio
|
||||
import board
|
||||
import adafruit_irremote
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
# Create a 'pulseio' input, to listen to infrared signals on the IR receiver
|
||||
pulsein = pulseio.PulseIn(board.IR_RX, maxlen=120, idle_state=True)
|
||||
# Create a decoder that will take pulses and turn them into numbers
|
||||
decoder = adafruit_irremote.GenericDecode()
|
||||
|
||||
while True:
|
||||
cpx.red_led = True
|
||||
pulses = decoder.read_pulses(pulsein)
|
||||
try:
|
||||
# Attempt to convert received pulses into numbers
|
||||
received_code = decoder.decode_bits(pulses, debug=False)
|
||||
except adafruit_irremote.IRNECRepeatException:
|
||||
# We got an unusual short code, probably a 'repeat' signal
|
||||
continue
|
||||
except adafruit_irremote.IRDecodeException:
|
||||
# Something got distorted
|
||||
continue
|
||||
|
||||
print("Infrared code received: ", received_code)
|
||||
if received_code == [66, 84, 78, 65]:
|
||||
print("Button A signal")
|
||||
cpx.pixels.fill((100, 0, 155))
|
||||
if received_code == [66, 84, 78, 64]:
|
||||
print("Button B Signal")
|
||||
cpx.pixels.fill((210, 45, 0))
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
"""THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE.
|
||||
This example requires the adafruit_irremote.mpy library.
|
||||
|
||||
This example uses the IR transmitter found near the center of the board. Works with another CPX
|
||||
running the cpx_ir_receive.py example. Press the buttons to light up the NeoPixels on the RECEIVING
|
||||
CPX!"""
|
||||
import time
|
||||
import pulseio
|
||||
import board
|
||||
import adafruit_irremote
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
# Create a 'pulseio' output, to send infrared signals from the IR transmitter
|
||||
pwm = pulseio.PWMOut(board.IR_TX, frequency=38000, duty_cycle=2 ** 15)
|
||||
pulseout = pulseio.PulseOut(pwm)
|
||||
# Create an encoder that will take numbers and turn them into NEC IR pulses
|
||||
encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500], one=[550, 550],
|
||||
zero=[550, 1700], trail=0)
|
||||
|
||||
while True:
|
||||
if cpx.button_a:
|
||||
print("Button A pressed! \n")
|
||||
cpx.red_led = True
|
||||
encoder.transmit(pulseout, [66, 84, 78, 65])
|
||||
cpx.red_led = False
|
||||
# wait so the receiver can get the full message
|
||||
time.sleep(0.2)
|
||||
if cpx.button_b:
|
||||
print("Button B pressed! \n")
|
||||
cpx.red_led = True
|
||||
encoder.transmit(pulseout, [66, 84, 78, 64])
|
||||
cpx.red_led = False
|
||||
time.sleep(0.2)
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
"""This example uses the light sensor on your CPX, located next to the picture of the eye. Try
|
||||
shining a flashlight on your CPX, or covering the light sensor with your finger to see the values
|
||||
increase and decrease."""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
print("Light:", cpx.light)
|
||||
time.sleep(1)
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
"""THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE.
|
||||
This example requires the simpleio.mpy library.
|
||||
|
||||
This example uses the light sensor on the CPX, located net to the picture of the eye on the board.
|
||||
Once you have the library loaded, try shining a flashlight on your CPX to watch the number of
|
||||
NeoPixels lit up increase, or try covering up the light sensor to watch the number decrease."""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
import simpleio
|
||||
|
||||
cpx.pixels.auto_write = False
|
||||
cpx.pixels.brightness = 0.3
|
||||
|
||||
while True:
|
||||
# light value remapped to pixel position
|
||||
peak = simpleio.map_range(cpx.light, 0, 320, 0, 10)
|
||||
print(cpx.light)
|
||||
print(int(peak))
|
||||
|
||||
for i in range(0, 10, 1):
|
||||
if i <= peak:
|
||||
cpx.pixels[i] = (0, 255, 255)
|
||||
else:
|
||||
cpx.pixels[i] = (0, 0, 0)
|
||||
cpx.pixels.show()
|
||||
time.sleep(0.05)
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
"""If you're using Mu, this example will plot the light levels from the light sensor (located next
|
||||
to the eye) on your CPX. Try shining a flashlight on your CPX, or covering the light sensor to see
|
||||
the plot increase and decrease."""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
print("Light:", cpx.light)
|
||||
print((cpx.light,))
|
||||
time.sleep(0.1)
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
"""This example lights up the first and second NeoPixel, red and blue respectively."""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.pixels.brightness = 0.3
|
||||
|
||||
while True:
|
||||
cpx.pixels[0] = (255, 0, 0)
|
||||
cpx.pixels[1] = (0, 0, 255)
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
# CircuitPython demo - NeoPixel
|
||||
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
# The number of pixels in the strip
|
||||
numpix = 10
|
||||
|
||||
|
||||
def wheel(pos):
|
||||
# Input a value 0 to 255 to get a color value.
|
||||
# The colours are a transition r - g - b - back to r.
|
||||
if (pos < 0) or (pos > 255):
|
||||
return (0, 0, 0)
|
||||
if pos < 85:
|
||||
return (int(pos * 3), int(255 - (pos*3)), 0)
|
||||
if pos < 170:
|
||||
pos -= 85
|
||||
return (int(255 - pos*3), 0, int(pos*3))
|
||||
pos -= 170
|
||||
return (0, int(pos*3), int(255 - pos*3))
|
||||
|
||||
|
||||
def rainbow_cycle(wait):
|
||||
for j in range(255):
|
||||
for i in range(cpx.pixels.n):
|
||||
idx = int((i * 256 / len(cpx.pixels)) + j)
|
||||
cpx.pixels[i] = wheel(idx & 255)
|
||||
cpx.pixels.show()
|
||||
time.sleep(wait)
|
||||
|
||||
|
||||
cpx.pixels.auto_write = False
|
||||
cpx.pixels.brightness = 0.3
|
||||
while True:
|
||||
rainbow_cycle(0.001) # rainbowcycle with 1ms delay per step
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
"""THIS EXAMPLE REQUIRES A WAV FILE FROM THE examples FOLDER IN THE
|
||||
Adafruit_CircuitPython_CircuitPlayground REPO found at:
|
||||
https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples
|
||||
|
||||
Copy the "dip.wav" file to your CIRCUITPY drive.
|
||||
|
||||
Once the file is copied, this example plays a wav file!"""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.play_file("dip.wav")
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
"""THIS EXAMPLE REQUIRES A WAV FILE FROM THE examples FOLDER IN THE
|
||||
Adafruit_CircuitPython_CircuitPlayground REPO found at:
|
||||
https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples
|
||||
|
||||
Copy the "dip.wav" and "rise.wav" files to your CIRCUITPY drive.
|
||||
|
||||
Once the files are copied, this example plays a different wav file for each button pressed!"""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
if cpx.button_a:
|
||||
cpx.play_file("dip.wav")
|
||||
if cpx.button_b:
|
||||
cpx.play_file("rise.wav")
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
"""This example plays two tones for 1 second each. Note that the tones are not in a loop - this is
|
||||
to prevent them from playing indefinitely!"""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.play_tone(262, 1)
|
||||
cpx.play_tone(294, 1)
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
"""This example plays a different tone for a duration of 1 second for each button pressed."""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
if cpx.button_a:
|
||||
cpx.play_tone(262, 1)
|
||||
if cpx.button_b:
|
||||
cpx.play_tone(294, 1)
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
"""This example turns on the little red LED."""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
cpx.red_led = True
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
"""This is the "Hello, world!" of CircuitPython: Blinky! This example blinks the little red LED on
|
||||
and off!"""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
cpx.red_led = True
|
||||
time.sleep(0.5)
|
||||
cpx.red_led = False
|
||||
time.sleep(0.5)
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
"""This is the "Hello, world!" of CircuitPython: Blinky! This example blinks the little red LED on
|
||||
and off! It's a shorter version of the other Blinky example."""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
cpx.red_led = not cpx.red_led
|
||||
time.sleep(0.5)
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
if cpx.shake(shake_threshold=20):
|
||||
print("Shake detected!")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
"""This example prints the status of the slide switch. Try moving the switch back and forth to see
|
||||
what's printed to the serial console!"""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
print("Slide switch:", cpx.switch)
|
||||
time.sleep(0.1)
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
"""This example uses the slide switch to control the little red LED."""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
# This code is written to be readable versus being Pylint compliant.
|
||||
# pylint: disable=simplifiable-if-statement
|
||||
|
||||
while True:
|
||||
if cpx.switch:
|
||||
cpx.red_led = True
|
||||
else:
|
||||
cpx.red_led = False
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
"""This example uses the slide switch to control the little red LED. When the switch is to the
|
||||
right it returns False, and when it's to the left, it returns True."""
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
cpx.red_led = cpx.switch
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
"""This example uses the sound sensor, located next to the picture of the ear on your board, to
|
||||
light up the NeoPixels as a sound meter. Try talking to your CPX or clapping, etc, to see the
|
||||
NeoPixels light up!"""
|
||||
import array
|
||||
import math
|
||||
import audiobusio
|
||||
import board
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
|
||||
def constrain(value, floor, ceiling):
|
||||
return max(floor, min(value, ceiling))
|
||||
|
||||
|
||||
def log_scale(input_value, input_min, input_max, output_min, output_max):
|
||||
normalized_input_value = (input_value - input_min) / (input_max - input_min)
|
||||
return output_min + math.pow(normalized_input_value, 0.630957) * (output_max - output_min)
|
||||
|
||||
|
||||
def normalized_rms(values):
|
||||
minbuf = int(sum(values) / len(values))
|
||||
return math.sqrt(sum(float(sample - minbuf) *
|
||||
(sample - minbuf) for sample in values) / len(values))
|
||||
|
||||
|
||||
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
|
||||
sample_rate=16000, bit_depth=16)
|
||||
|
||||
samples = array.array('H', [0] * 160)
|
||||
mic.record(samples, len(samples))
|
||||
input_floor = normalized_rms(samples) + 10
|
||||
|
||||
# Lower number means more sensitive - more LEDs will light up with less sound.
|
||||
sensitivity = 500
|
||||
input_ceiling = input_floor + sensitivity
|
||||
|
||||
peak = 0
|
||||
while True:
|
||||
mic.record(samples, len(samples))
|
||||
magnitude = normalized_rms(samples)
|
||||
print((magnitude,))
|
||||
|
||||
c = log_scale(constrain(magnitude, input_floor, input_ceiling),
|
||||
input_floor, input_ceiling, 0, 10)
|
||||
|
||||
cpx.pixels.fill((0, 0, 0))
|
||||
for i in range(10):
|
||||
if i < c:
|
||||
cpx.pixels[i] = (i * (255 // 10), 50, 0)
|
||||
if c >= peak:
|
||||
peak = min(c, 10 - 1)
|
||||
elif peak > 0:
|
||||
peak = peak - 1
|
||||
if peak > 0:
|
||||
cpx.pixels[int(peak)] = (80, 0, 255)
|
||||
cpx.pixels.show()
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
"""This example turns on the little red LED and prints to the serial console when you double-tap
|
||||
the CPX!"""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
# Change to 1 for detecting a single-tap!
|
||||
cpx.detect_taps = 2
|
||||
|
||||
while True:
|
||||
if cpx.tapped:
|
||||
print("Tapped!")
|
||||
cpx.red_led = True
|
||||
time.sleep(0.1)
|
||||
else:
|
||||
cpx.red_led = False
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.detect_taps = 1
|
||||
|
||||
while True:
|
||||
if cpx.tapped:
|
||||
print("Single tap detected!")
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
# Set to check for single-taps.
|
||||
cpx.detect_taps = 1
|
||||
tap_count = 0
|
||||
|
||||
# We're looking for 2 single-taps before moving on.
|
||||
while tap_count < 2:
|
||||
if cpx.tapped:
|
||||
tap_count += 1
|
||||
print("Reached 2 single-taps!")
|
||||
|
||||
# Now switch to checking for double-taps
|
||||
tap_count = 0
|
||||
cpx.detect_taps = 2
|
||||
|
||||
# We're looking for 2 double-taps before moving on.
|
||||
while tap_count < 2:
|
||||
if cpx.tapped:
|
||||
tap_count += 1
|
||||
print("Reached 2 double-taps!")
|
||||
print("Done.")
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
"""THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE.
|
||||
This example requires the simpleio.mpy library.
|
||||
|
||||
This example use the temperature sensor on the CPX, located next to the picture of the thermometer
|
||||
on the board. Try warming up the board to watch the number of NeoPixels lit up increase, or cooling
|
||||
it down to see the number decrease. You can set the min and max temperatures to make it more or
|
||||
less sensitive to temperature changes.
|
||||
"""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
import simpleio
|
||||
|
||||
cpx.pixels.auto_write = False
|
||||
cpx.pixels.brightness = 0.3
|
||||
|
||||
# Set these based on your ambient temperature in Celsius for best results!
|
||||
minimum_temp = 24
|
||||
maximum_temp = 30
|
||||
|
||||
while True:
|
||||
# temperature value remapped to pixel position
|
||||
peak = simpleio.map_range(cpx.temperature, minimum_temp, maximum_temp, 0, 10)
|
||||
print(cpx.temperature)
|
||||
print(int(peak))
|
||||
|
||||
for i in range(0, 10, 1):
|
||||
if i <= peak:
|
||||
cpx.pixels[i] = (0, 255, 255)
|
||||
else:
|
||||
cpx.pixels[i] = (0, 0, 0)
|
||||
cpx.pixels.show()
|
||||
time.sleep(0.05)
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
"""This example uses the temperature sensor on the CPX, located next to the image of a thermometer
|
||||
on the board. It prints the temperature in both C and F to the serial console. Try putting your
|
||||
finger over the sensor to see the numbers change!"""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
print("Temperature C:", cpx.temperature)
|
||||
print("Temperature F:", cpx.temperature * 1.8 + 32)
|
||||
time.sleep(1)
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
"""If you're using Mu, this example will plot the temperature in C and F on the plotter! Click
|
||||
"Plotter" to open it, and place your finger over the sensor to see the numbers change. The
|
||||
sensor is located next to the picture of the thermometer on the CPX."""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
print("Temperature C:", cpx.temperature)
|
||||
print("Temperature F:", cpx.temperature * 1.8 + 32)
|
||||
print((cpx.temperature, cpx.temperature * 1.8 + 32))
|
||||
time.sleep(0.1)
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
if cpx.button_a:
|
||||
cpx.start_tone(262)
|
||||
elif cpx.button_b:
|
||||
cpx.start_tone(294)
|
||||
else:
|
||||
cpx.stop_tone()
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
"""This example uses the capacitive touch pads on the CPX. They are located around the outer edge
|
||||
of the board and are labeled A1-A7. (A0 is not a touch pad.) This example lights up all the
|
||||
NeoPixels a different color of the rainbow for each pad touched!"""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.pixels.brightness = 0.3
|
||||
|
||||
while True:
|
||||
if cpx.touch_A1:
|
||||
print("Touched A1!")
|
||||
cpx.pixels.fill((255, 0, 0))
|
||||
if cpx.touch_A2:
|
||||
print("Touched A2!")
|
||||
cpx.pixels.fill((210, 45, 0))
|
||||
if cpx.touch_A3:
|
||||
print("Touched A3!")
|
||||
cpx.pixels.fill((155, 100, 0))
|
||||
if cpx.touch_A4:
|
||||
print("Touched A4!")
|
||||
cpx.pixels.fill((0, 255, 0))
|
||||
if cpx.touch_A5:
|
||||
print("Touched A5!")
|
||||
cpx.pixels.fill((0, 135, 125))
|
||||
if cpx.touch_A6:
|
||||
print("Touched A6!")
|
||||
cpx.pixels.fill((0, 0, 255))
|
||||
if cpx.touch_A7:
|
||||
print("Touched A7!")
|
||||
cpx.pixels.fill((100, 0, 155))
|
||||
time.sleep(0.1)
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
"""This example uses the capacitive touch pads on the CPX. They are located around the outer edge
|
||||
of the board and are labeled A1-A7. (A0 is not a touch pad.) This example lights up the nearest
|
||||
NeoPixel to that pad a different color of the rainbow!"""
|
||||
import time
|
||||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
cpx.pixels.brightness = 0.3
|
||||
|
||||
while True:
|
||||
if cpx.touch_A1:
|
||||
print("Touched A1!")
|
||||
cpx.pixels[6] = (255, 0, 0)
|
||||
if cpx.touch_A2:
|
||||
print("Touched A2!")
|
||||
cpx.pixels[8] = (210, 45, 0)
|
||||
if cpx.touch_A3:
|
||||
print("Touched A3!")
|
||||
cpx.pixels[9] = (155, 100, 0)
|
||||
if cpx.touch_A4:
|
||||
print("Touched A4!")
|
||||
cpx.pixels[0] = (0, 255, 0)
|
||||
if cpx.touch_A5:
|
||||
print("Touched A5!")
|
||||
cpx.pixels[1] = (0, 135, 125)
|
||||
if cpx.touch_A6:
|
||||
print("Touched A6!")
|
||||
cpx.pixels[3] = (0, 0, 255)
|
||||
if cpx.touch_A7:
|
||||
print("Touched A7!")
|
||||
cpx.pixels[4] = (100, 0, 155)
|
||||
time.sleep(0.1)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
from adafruit_circuitplayground.express import cpx
|
||||
|
||||
while True:
|
||||
if cpx.touch_A1:
|
||||
print('Touched pad A1')
|
||||
if cpx.touch_A2:
|
||||
print('Touched pad A2')
|
||||
if cpx.touch_A3:
|
||||
print('Touched pad A3')
|
||||
if cpx.touch_A4:
|
||||
print('Touched pad A4')
|
||||
if cpx.touch_A5:
|
||||
print('Touched pad A5')
|
||||
if cpx.touch_A6:
|
||||
print('Touched pad A6')
|
||||
if cpx.touch_A7:
|
||||
print('Touched pad A7')
|
||||