Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cedargrovestudios/circuitpython_rangeslicer
A CircuitPython class for scaling a range of input values into indexed/quantized output values. Adjustable output slice hysteresis for noise reduction.
https://github.com/cedargrovestudios/circuitpython_rangeslicer
circuitpython circuitpython-community-bundle quantizer
Last synced: about 2 months ago
JSON representation
A CircuitPython class for scaling a range of input values into indexed/quantized output values. Adjustable output slice hysteresis for noise reduction.
- Host: GitHub
- URL: https://github.com/cedargrovestudios/circuitpython_rangeslicer
- Owner: CedarGroveStudios
- License: mit
- Created: 2022-09-15T01:04:58.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-27T07:15:00.000Z (about 1 year ago)
- Last Synced: 2023-12-27T08:26:09.842Z (about 1 year ago)
- Topics: circuitpython, circuitpython-community-bundle, quantizer
- Language: Python
- Homepage:
- Size: 24.9 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Introduction
============.. image:: https://img.shields.io/discord/327254708534116352.svg
:target: https://adafru.it/discord
:alt: Discord.. image:: https://github.com/CedarGroveStudios/Cedargrove_CircuitPython_RangeSlicer/workflows/Build%20CI/badge.svg
:target: https://github.com/CedarGroveStudios/Cedargrove_CircuitPython_RangeSlicer/actions
:alt: Build Status.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: Code Style: BlackRangeSlicer is a general-purpose CircuitPython analog value converter that linearly scales the input then quantizes it into a collection of precise output slice values. The class detects input value changes and applies selectable hysteresis when slice edge thresholds are reached to eliminate dead-zone noise issues without filtering delays. Applications include converting rotary knob position to discrete ranges of MIDI values, analog signal noise processing, level detection, rotary switch emulation, and signal display.
.. image:: https://github.com/CedarGroveStudios/CircuitPython_RangeSlicer/blob/master/media/range_slicer_models.png
:alt: RangeSlicer Signal ModelsThe effect of using hysteresis to clean up a noisy signal:
.. image:: https://github.com/CedarGroveStudios/CircuitPython_RangeSlicer/blob/master/media/range_slicer_noise_models.png
:alt: RangeSlicer Noise ModelsDependencies
=============
This driver depends on:* `Adafruit CircuitPython `_
Please ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloading
`the Adafruit library and driver bundle `_
or individual libraries can be installed using
`circup `_.Installing to a Connected CircuitPython Device with Circup
==========================================================Make sure that you have ``circup`` installed in your Python environment.
Install it with the following command if necessary:.. code-block:: shell
pip3 install circup
With ``circup`` installed and your CircuitPython device connected use the
following command to install:.. code-block:: shell
circup install cedargrove_rangeslicer
Or the following command to update an existing version:
.. code-block:: shell
circup update
Usage Example
=============.. code-block:: Python
"""Reads two potentiometer inputs and produces -1.0 to +1.0 normalized outputs,
one with an inverted output range."""import time
import board
from analogio import AnalogIn
import cedargrove_rangeslicer as rsprint("Two Normalized Outputs: RangeSlicer example 01")
"""Establish range_slicer instances, one for each analog potentiometer
input. Input ranges are adjusted for unique potentiometer inaccuracies and
noise. Slice size divides the output into 10 slices. Hysteresis factor is
25% of a slice."""ctrl_0 = rs.Slicer(200, 65335, -1.0, +1.0, 0.2, 0.25)
ctrl_1 = rs.Slicer(375, 65520, +1.0, -1.0, 0.2, 0.25)# establish analog inputs
pot_0 = AnalogIn(board.A0)
pot_1 = AnalogIn(board.A1)while True: # read potentiometer values
control_0 = pot_0.value
control_1 = pot_1.value# calculate output values and print (or plot in Mu)
out_0 = ctrl_0.range_slicer(control_0)
out_1 = ctrl_1.range_slicer(control_1)
print( (control_0 / 65535, control_1 / 65535, out_0, out_1) )time.sleep(0.1) # pause for 0.1 second
Documentation
=============
`RangeSlicer CircuitPython Driver API Class Description `_Contributing
============Contributions are welcome! Please read our `Code of Conduct
`_
before contributing to help this project stay welcoming.