diff --git a/README.rst b/README.rst index c7b1fd5..ebf7cc4 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ picozero |pypibadge| |docsbadge| -A beginner-friendly library for using common electronics components with the Raspberry Pi Pico. +A beginner-friendly library to help you use common electronics components with the Raspberry Pi Pico. .. code-block:: python @@ -23,7 +23,7 @@ Beta. There will be bugs and issues. API changes are likely. More devices will b Documentation ------------- -Documentation is available at `picozero.readthedocs.io `_ : +Documentation is available at `picozero.readthedocs.io `_: - `Installation and getting started guide `_ - `Recipes and how-to's `_ @@ -34,7 +34,7 @@ Code The code and project is at `github.com/RaspberryPiFoundation/picozero `_. -Issues can be raised at `github.com/RaspberryPiFoundation/picozero/issues `_ (see `contributing `_). +Issues can be raised at `github.com/RaspberryPiFoundation/picozero/issues `_ (see `Contributing `_). The latest distribution is available at `pypi.org/project/picozero/ `_. diff --git a/docs/changelog.rst b/docs/changelog.rst index 3e77dde..ea71046 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -12,41 +12,41 @@ Change log 0.3.0 - 2022-08-12 ~~~~~~~~~~~~~~~~~~ -+ Introduced ``Motor``, ``Robot`` and ``DistanceSensor`` classes. -+ Renamed ``LED`` factory ``use_pwm`` parameter to ``pwm`` to match other classes. Note - this is an API breaking change. ++ Introduced ``Motor``, ``Robot``, and ``DistanceSensor`` classes. ++ Renamed ``LED`` factory ``use_pwm`` parameter to ``pwm`` to match other classes. **Note:** This is an API breaking change. + Resolved issue with ``RGBLED`` when not using ``pwm``. + Resolved issue where ``blink`` / ``pulse`` rates of ``0`` raised a traceback error. -+ Other minor bug fixes -+ Documentation updates ++ Other minor bug fixes. ++ Documentation updates. 0.2.0 - 2022-06-29 ~~~~~~~~~~~~~~~~~~ -+ Pico W compatibility fix for onboard LED ++ Pico W compatibility fix for onboard LED. 0.1.1 - 2022-06-08 ~~~~~~~~~~~~~~~~~~ -+ Minor bug fixes found during testing -+ Small improvements to exception messages -+ Added close methods to Speaker and PWMOutputDevice -+ Added unit tests -+ Added RGBLED.colour as an alias to RGBLED.color ++ Minor fixes for bugs found during testing. ++ Small improvements to exception messages. ++ Added close methods to Speaker and PWMOutputDevice. ++ Added unit tests. ++ Added RGBLED.colour as an alias to RGBLED.color. 0.1.0 - 2022-04-08 ~~~~~~~~~~~~~~~~~~ -+ Beta release -+ Documentation update -+ Minor bug fixes and refactoring ++ Beta release. ++ Documentation updates. ++ Minor bug fixes and refactoring. 0.0.2 - 2022-03-31 ~~~~~~~~~~~~~~~~~~ -+ Bug fixes and documentation updates ++ Bug fixes and documentation updates. 0.0.1 - 2022-03-21 ~~~~~~~~~~~~~~~~~~ -+ Initial alpha release to test installation process ++ Initial alpha release to test installation process. diff --git a/docs/contributing.rst b/docs/contributing.rst index 93938d8..3e68105 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -1,20 +1,19 @@ Contributing ============ -Contributions to the picozero are welcome. Here is some advice. +Contributions to picozero are welcome. Please keep in mind that picozero is 'lightweight'. It is designed to be easy to use but also needs to run on a microcontroller; please take this into account when considering feature requests or raising issues. -1. picozero is 'lightweight', it is designed to be easy to use but also needs to run on a micro controller, please take this into account when considering feature requests or raising issues. -2. see below for other stuff! +For more details, please see the following advice. Status ------ -picozero is currently in Beta, pre release 1.0, you should consider the following: +As picozero is currently in Beta, pre-release 1.0, you should consider the following: - The API is not yet set, however, this doesn't mean that backwards compatibility is not important! It is a balancing act. - Requests for new features will need to be prioritised and responses to feature requests may take some time. -- Refactoring of the code base is very likely and as a result pull requests may need rework. -- Issues are likely to exist within the code base, be kind! +- Refactoring of the code base is very likely and, as a result, pull requests may need rework. +- Issues are likely to exist within the code base. Be kind! Suggestions ----------- @@ -31,4 +30,4 @@ Pull requests All pull requests should be based on the `dev `_ branch of picozero. -.. _issue: https://github.com/RaspberryPiFoundation/picozero/issues \ No newline at end of file +.. _issue: https://github.com/RaspberryPiFoundation/picozero/issues diff --git a/docs/developing.rst b/docs/developing.rst index 37b53d7..a5c6935 100644 --- a/docs/developing.rst +++ b/docs/developing.rst @@ -13,11 +13,11 @@ To build and deploy picozero, you need to install the dependencies :: Build ----- -1. Update version numbers in the ``setup.py``, ``picozero/__init__.py`` and ``docs/conf.py`` files. +1. Update version numbers in the ``setup.py``, ``picozero/__init__.py``, and ``docs/conf.py`` files 2. Add release to ``docs/changelog.rst`` -3. Run `setup.py` and create a source distribution :: +3. Run ``setup.py`` and create a source distribution :: python3 setup.py sdist @@ -27,7 +27,7 @@ Build 5. Push all changes to ``master`` branch -6. Create a `release `_ in github and upload ``picozero-#-#-#.tar.gz`` source file to the release. +6. Create a `release `_ in github and upload ``picozero-#-#-#.tar.gz`` source file to the release Documentation ------------- @@ -51,17 +51,17 @@ Documentation can be viewed at `picozero.readthedocs.io`_ and is automatically b Tests ----- -The tests are design to be run on a Raspberry Pi Pico. +The tests are designed to be run on a Raspberry Pi Pico. -1. Install the `picozero `_ package. +1. Install the `picozero `_ package -2. Install the `micropython-unittest `_ package. +2. Install the `micropython-unittest `_ package -3. Copy the ``test_picozero.py`` to the pico. +3. Copy the ``test_picozero.py`` file to the Pico -4. Run the ``test_picozero.py`` file. +4. Run the ``test_picozero.py`` file -If a test fails it is helpful to be able to see verbose error messages. To see error messages you need to modify the ``lib/unittest.py`` file on the pico. +If a test fails, it is helpful to be able to see verbose error messages. To see error messages, you need to modify the ``lib/unittest.py`` file on the Pico. Locate the following code in the ``run_class`` function:: @@ -71,4 +71,4 @@ Locate the following code in the ``run_class`` function:: Uncomment ``raise``:: # Uncomment to investigate failure in detail - raise \ No newline at end of file + raise diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst index 29af398..b994471 100644 --- a/docs/gettingstarted.rst +++ b/docs/gettingstarted.rst @@ -2,52 +2,52 @@ .. .. SPDX short identifier: MIT -Getting Started +Getting started =============== Requirements ------------ -A Windows, macOS or Linux computer with the `Thonny Python IDE`_ installed. +A Windows, macOS, or Linux computer with the `Thonny Python IDE`_ installed. .. _Thonny Python IDE: https://thonny.org/ -You can find information on how to install Thonny on the `Introduction to Raspberry Pi Pico guide`_. +You can find information on how to install Thonny in the `Introduction to Raspberry Pi Pico guide`_. .. _Introduction to Raspberry Pi Pico guide: https://learning-admin.raspberrypi.org/en/projects/introduction-to-the-pico/2 -Once Thonny is installed you will need to ensure that you are using the latest MicroPython firmware. Details on how to install or update the Raspberry Pi Pico MicroPython firmware can be found on the `guide`_. +Once Thonny is installed, you will need to ensure that you are using the latest MicroPython firmware. Details on how to install or update the Raspberry Pi Pico MicroPython firmware can be found in the `Pico guide`_. -.. _guide: https://learning-admin.raspberrypi.org/en/projects/introduction-to-the-pico/3 +.. _Pico guide: https://learning-admin.raspberrypi.org/en/projects/introduction-to-the-pico/3 Use the MicroPython interpreter ------------------------------- -In Thonny, on the bottom right of the screen, there are options for changing the interpreter that you are using. Make sure that **MicroPython (Raspberry Pi Pico)** is selected. +You can change which interpreter you are using in Thonny by selecting the desired option at the bottom right of the screen. Make sure that **MicroPython (Raspberry Pi Pico)** is selected. .. image:: images/thonny-switch-interpreter.jpg -Install picozero from PyPi in Thonny +Install picozero from PyPI in Thonny ------------------------------------ -To install picozero within Thonny select **Tools** > **Manage packages...** +To install picozero within Thonny, select **Tools** > **Manage packages...** .. image:: images/thonny-manage-packages.jpg -Search for `picozero` on PyPi. +Search for `picozero` on PyPI. .. image:: images/thonny-packages-picozero.jpg -Click on install to download the package. +Click on **install** to download the package. .. image:: images/thonny-install-package.jpg Other install options --------------------- -You can use the Thonny file manager to transfer a ``picozero.py`` file to Raspberry Pi Pico. +You can use the Thonny file manager to transfer a ``picozero.py`` file to your Raspberry Pi Pico. -From the **View** menu, choose to see files. +In the **View** menu, ensure that the **Files** option has a tick. This will let you see the files. .. image:: images/thonny-view-files.jpg @@ -56,11 +56,11 @@ Either clone the picozero `GitHub repository`_ or copy the code from the `picoze .. _GitHub repository: https://github.com/RaspberryPiFoundation/picozero .. _picozero.py: https://raw.githubusercontent.com/RaspberryPiFoundation/picozero/master/picozero/picozero.py?token=GHSAT0AAAAAABRLTKWZDBSYBE54NJ7AIZ6MYSENI2A -In Thonny, navigate to the cloned directory or location you save the file to find the ``picozero.py`` file. +In Thonny, navigate to the cloned directory or location you saved the file in and find the ``picozero.py`` file. .. image:: images/thonny-navigate-downloads.jpg -Right click on the file and select the **Upload to /** option and you should see a copy of the ``picozero.py`` file on Raspberry Pi Pico. +Right click on the file and select the **Upload to /** option. You should see a copy of the ``picozero.py`` file on the Raspberry Pi Pico. .. image:: images/thonny-upload-files.jpg .. image:: images/thonny-copy-picozero.jpg @@ -84,7 +84,7 @@ Run a program on your computer You can choose to run the program from your computer. -Click on the **Run current script button**. +Click on the **Run current script** button. .. image:: images/run-current-script.jpg @@ -92,12 +92,12 @@ Choose to save the script on **This computer** and provide a filename. .. image:: images/save-this-computer.png -Run a program on Raspberry Pi Pico +Run a program on your Raspberry Pi Pico ---------------------------------- -You can choose to run the program from Raspberry Pi Pico. +You can choose to run the program from the Raspberry Pi Pico. -Click on the **Run current script button**. +Click on the **Run current script** button. .. image:: images/run-current-script.jpg @@ -105,4 +105,4 @@ Choose to save the script on **Raspberry Pi Pico** and provide a filename. .. image:: images/save-this-raspberry-pi-pico.png -If you call the file ``main.py`` it will run automatically when the Pico is powered. \ No newline at end of file +If you call the file ``main.py``, it will run automatically when the Pico is powered on. diff --git a/docs/recipes.rst b/docs/recipes.rst index e8221f2..e39513b 100644 --- a/docs/recipes.rst +++ b/docs/recipes.rst @@ -3,14 +3,14 @@ Recipes The recipes provide examples of how you can use picozero. -Importing Pico Zero +Importing picozero ------------------- .. currentmodule:: picozero -You will need add an `import` line to the top of your script to use Pico Zero. +You will need add an `import` line to the top of your script to use picozero. -You can import just what you need, separating items with a comma `,`:: +You can import just what you need, separating items with a comma ``,``:: from picozero import pico_led, LED @@ -20,11 +20,11 @@ Now you can use :obj:`~picozero.pico_led` and :class:`~picozero.LED` in your scr led = LED(14) # Control an LED connected to pin GP14 led.on() -Alternatively, the whole Pico Zero library can be imported:: +Alternatively, the whole picozero library can be imported:: import picozero -In this case, all references to Pico Zero items must be prefixed:: +In this case, all references to picozero items must be prefixed:: picozero.pico_led.on() led = picozero.LED(14) @@ -34,9 +34,9 @@ Pico LED -------- .. image:: images/pico_led.svg - :alt: A diagram of the Raspberry Pi Pico with a GP25 label attached to the onboard LED + :alt: A diagram of the Raspberry Pi Pico with a GP25 label attached to the onboard LED. -To turn on the LED on Raspberry Pi Pico: +To turn on the LED on your Raspberry Pi Pico: .. literalinclude:: examples/pico_led.py @@ -48,11 +48,11 @@ Using the :obj:`pico_led` is equivalent to:: You can use :obj:`pico_led` in the same way as external LEDs created using :class:`LED`. -LED +LEDs ------ .. image:: images/pico_led_14_bb.svg - :alt: A diagram of the Raspberry Pi Pico with yellow LED connected to GP14 and GND. + :alt: A diagram of the Raspberry Pi Pico with a yellow LED connected to GP14 and GND. You can control external LEDs with a Raspberry Pi Pico. @@ -82,10 +82,10 @@ Create a pulse effect: .. literalinclude:: examples/led_pulse.py -Button +Buttons ------ -You can connect buttons and switches to a Raspberry Pi Pico and detect whether they are pressed. +You can connect buttons and switches to a Raspberry Pi Pico and detect when they are pressed. Check if a :class:`Button` is pressed: @@ -102,14 +102,14 @@ Run a function every time a :class:`Button` is pressed: function ``led_on_off``, rather it creates a reference to the function to be called when the button is pressed. Accidental use of ``button.when_pressed = led_on_off()`` would set the ``when_pressed`` action to :data:`None` (the - return value of this function) which would mean nothing happens when the + return value of this function), which would mean nothing happens when the button is pressed. Turn the :obj:`pico_led` on when a :class:`Button` is pressed and off when it is released: .. literalinclude:: examples/button_led.py -RGBLED +RGB LEDs ------ Set colours with an :class:`RGBLED`: @@ -132,7 +132,7 @@ You can control whether :meth:`~picozero.RGBLED.blink` runs a fixed number of ti Pulse ~~~~~ -Use :meth:`~picozero.RGBLED.pulse` to gradually change the LED between colours. The default will pulse between red and off, then green and off, then blue and off. +Use :meth:`~picozero.RGBLED.pulse` to gradually change the LED colour. The default will pulse between red and off, then green and off, then blue and off. .. literalinclude:: examples/rgb_pulse.py @@ -146,13 +146,13 @@ The default for :meth:`~picozero.RGBLED.cycle` is to cycle from red to green, th Potentiometer --------------- -Print the value, voltage and percent reported by a potentiometer: +Print the value, voltage, and percent reported by a potentiometer: .. literalinclude:: examples/potentiometer.py .. note:: - In the Thonny Python editor, choose View->Plotter to plot the output of :meth:`print`. + In the Thonny Python editor, choose **View** > **Plotter** to plot the output of :meth:`print`. Use a potentiometer to control the brightness of an LED: @@ -209,39 +209,39 @@ Move the servo gradually from its minimum to maximum position in 100 increments. Motor ----- -Move a motor which is connected via 2 pins (forward / backward) and a motor controller board +Move a motor connected via two pins (forward and backward) and a motor controller board: .. literalinclude:: examples/motor_move.py Robot rover ------------- -Make a simple 2 wheeled robot rover. +Make a simple two-wheeled robot rover. .. image:: images/robot_bb.svg - :alt: A diagram of the Raspberry Pi Pico connected to 2 motors via a motor controller board powered by a battery pack + :alt: A diagram of the Raspberry Pi Pico connected to two motors via a motor controller board powered by a battery pack. -Move the rover forward for 1 second and stop. +Move the rover forward for 1 second and stop: .. literalinclude:: examples/robot_rover_forward.py -Move the rover *roughly* in a square: +Move the rover (roughly) in a square: .. literalinclude:: examples/robot_rover_square.py -Internal Temperature Sensor +Internal temperature sensor --------------------------- Check the internal temperature of the Raspberry Pi Pico in degrees Celcius: .. literalinclude:: examples/pico_temperature.py -Ultrasonic Distance Sensor +Ultrasonic distance sensor -------------------------- -Get the distance in metres from an ultrasonic distance sensor (HC-SR04). +Get the distance in metres from an ultrasonic distance sensor (HC-SR04): .. image:: images/distance_sensor_bb.svg - :alt: A diagram of the Raspberry Pi Pico connected to HC-SR04 distance sensor + :alt: A diagram of the Raspberry Pi Pico connected to an HC-SR04 distance sensor. -.. literalinclude:: examples/ultrasonic_distance_sensor.py \ No newline at end of file +.. literalinclude:: examples/ultrasonic_distance_sensor.py diff --git a/picozero/picozero.py b/picozero/picozero.py index 03370cf..886dcde 100644 --- a/picozero/picozero.py +++ b/picozero/picozero.py @@ -26,7 +26,7 @@ class PinMixin: @property def pin(self): """ - Returns the pin number used by the device + Returns the pin number used by the device. """ return self._pin_num @@ -35,13 +35,13 @@ def __str__(self): class PinsMixin: """ - Mixin used by devices that use multiple pins + Mixin used by devices that use multiple pins. """ @property def pins(self): """ - Returns a tuple of pins used by the device + Returns a tuple of pins used by the device. """ return self._pin_nums @@ -50,13 +50,13 @@ def __str__(self): class ValueChange: """ - Internal class to control the value of an output device + Internal class to control the value of an output device. :param OutputDevice output_device: - The OutputDevice object you wish to change the value of + The OutputDevice object you wish to change the value of. :param generator: - A generator function which yields a 2d list of + A generator function that yields a 2d list of ((value, seconds), *). The output_device's value will be set for the number of @@ -117,7 +117,7 @@ def _get_value(self): self._n = self._n - 1 if self._n is not None else None if self._n == 0: - # its the end, return None + # it's the end, return None return None else: # recreate the generator and start again @@ -150,7 +150,7 @@ def active_high(self): """ Sets or returns the active_high property. If :data:`True`, the :meth:`on` method will set the Pin to HIGH. If :data:`False`, - the :meth:`on` method will set the Pin toLOW (the :meth:`off` method + the :meth:`on` method will set the Pin to LOW (the :meth:`off` method always does the opposite). """ return self._active_state @@ -163,7 +163,7 @@ def active_high(self, value): @property def value(self): """ - Sets or returns a value representing the state of the device. 1 is on, 0 is off. + Sets or returns a value representing the state of the device: 1 is on, 0 is off. """ return self._read() @@ -180,12 +180,12 @@ def on(self, value=1, t=None, wait=False): The value to set when turning on. Defaults to 1. :param float t: - The time in seconds the device should be on. If None is + The time in seconds that the device should be on. If None is specified, the device will stay on. The default is None. :param bool wait: - If True the method will block until the time `t` has expired. - If False the method will return and the device will turn on in + If True, the method will block until the time `t` has expired. + If False, the method will return and the device will turn on in the background. Defaults to False. Only effective if `t` is not None. """ @@ -218,13 +218,13 @@ def toggle(self): def blink(self, on_time=1, off_time=None, n=None, wait=False): """ - Make the device turn on and off repeatedly. + Makes the device turn on and off repeatedly. :param float on_time: - The length of time in seconds the device will be on. Defaults to 1. + The length of time in seconds that the device will be on. Defaults to 1. :param float off_time: - The length of time in seconds the device will be off. If `None`, + The length of time in seconds that the device will be off. If `None`, it will be the same as ``on_time``. Defaults to `None`. :param int n: @@ -233,8 +233,8 @@ def blink(self, on_time=1, off_time=None, n=None, wait=False): is None. :param bool wait: - If True the method will block until the device stops turning on and off. - If False the method will return and the device will turn on and off in + If True, the method will block until the device stops turning on and off. + If False, the method will return and the device will turn on and off in the background. Defaults to False. """ off_time = on_time if off_time is None else off_time @@ -272,7 +272,7 @@ class DigitalOutputDevice(OutputDevice, PinMixin): LOW (the :meth:`off` method always does the opposite). :param bool initial_value: - If :data:`False` (the default), the LED will be off initially. If + If :data:`False` (the default), the LED will be off initially. If :data:`True`, the LED will be switched on initially. """ def __init__(self, pin, active_high=True, initial_value=False): @@ -302,7 +302,7 @@ def close(self): class DigitalLED(DigitalOutputDevice): """ - Represents a simple LED which can be switched on and off. + Represents a simple LED, which can be switched on and off. :param int pin: The pin that the device is connected to. @@ -313,7 +313,7 @@ class DigitalLED(DigitalOutputDevice): LOW (the :meth:`off` method always does the opposite). :param bool initial_value: - If :data:`False` (the default), the LED will be off initially. If + If :data:`False` (the default), the LED will be off initially. If :data:`True`, the LED will be switched on initially. """ pass @@ -322,7 +322,7 @@ class DigitalLED(DigitalOutputDevice): class Buzzer(DigitalOutputDevice): """ - Represents an active or passive buzzer which can be turned on or off. + Represents an active or passive buzzer, which can be turned on or off. :param int pin: The pin that the device is connected to. @@ -333,7 +333,7 @@ class Buzzer(DigitalOutputDevice): LOW (the :meth:`off` method always does the opposite). :param bool initial_value: - If :data:`False` (the default), the Buzzer will be off initially. If + If :data:`False` (the default), the Buzzer will be off initially. If :data:`True`, the Buzzer will be switched on initially. """ pass @@ -348,7 +348,7 @@ class PWMOutputDevice(OutputDevice, PinMixin): The pin that the device is connected to. :param int freq: - The frequency of the PWM signal in Hertz. Defaults to 100. + The frequency of the PWM signal in hertz. Defaults to 100. :param int duty_factor: The duty factor of the PWM signal. This is a value between 0 and 65535. @@ -360,8 +360,8 @@ class PWMOutputDevice(OutputDevice, PinMixin): LOW (the :meth:`off` method always does the opposite). :param bool initial_value: - If :data:`0` (the default), the device will be off initially. If - :data:`1`, the device will be switched on initially. + If :data:`False` (the default), the LED will be off initially. If + :data:`True`, the LED will be switched on initially. """ PIN_TO_PWM_CHANNEL = ["0A","0B","1A","1B","2A","2B","3A","3B","4A","4B","5A","5B","6A","6B","7A","7B","0A","0B","1A","1B","2A","2B","3A","3B","4A","4B","5A","5B","6A","6B"] @@ -422,7 +422,7 @@ def freq(self, freq): def blink(self, on_time=1, off_time=None, n=None, wait=False, fade_in_time=0, fade_out_time=None, fps=25): """ - Make the device turn on and off repeatedly. + Makes the device turn on and off repeatedly. :param float on_time: The length of time in seconds the device will be on. Defaults to 1. @@ -436,8 +436,8 @@ def blink(self, on_time=1, off_time=None, n=None, wait=False, fade_in_time=0, fa device will continue blinking forever. The default is `None`. :param bool wait: - If True the method will block until the LED stops blinking. If False - the method will return and the LED is will blink in the background. + If True, the method will block until the LED stops blinking. If False, + the method will return and the LED will blink in the background. Defaults to False. :param float fade_in_time: @@ -483,14 +483,14 @@ def blink_generator(): def pulse(self, fade_in_time=1, fade_out_time=None, n=None, wait=False, fps=25): """ - Make the device pulse on and off repeatedly. + Makes the device pulse on and off repeatedly. :param float fade_in_time: - The length of time in seconds the device will take to turn on. + The length of time in seconds that the device will take to turn on. Defaults to 1. :param float fade_out_time: - The length of time in seconds the device will take to turn off. + The length of time in seconds that the device will take to turn off. Defaults to 1. :param int fps: @@ -498,12 +498,12 @@ def pulse(self, fade_in_time=1, fade_out_time=None, n=None, wait=False, fps=25): steps between off/on states. Defaults to 25. :param int n: - The number of times to pulse the LED. If None the LED will pulse + The number of times to pulse the LED. If None, the LED will pulse forever. Defaults to None. :param bool wait: - If True the method will block until the LED stops pulsing. If False - the method will return and the LED is will pulse in the background. + If True, the method will block until the LED stops pulsing. If False, + the method will return and the LED will pulse in the background. Defaults to False. """ self.blink(on_time=0, off_time=0, fade_in_time=fade_in_time, fade_out_time=fade_out_time, n=n, wait=wait, fps=fps) @@ -522,13 +522,13 @@ def close(self): class PWMLED(PWMOutputDevice): """ - Represents an LED driven by a PWM pin whose brightness can be changed. + Represents an LED driven by a PWM pin; the brightness of the LED can be changed. :param int pin: The pin that the device is connected to. :param int freq: - The frequency of the PWM signal in Hertz. Defaults to 100. + The frequency of the PWM signal in hertz. Defaults to 100. :param int duty_factor: The duty factor of the PWM signal. This is a value between 0 and 65535. @@ -540,7 +540,7 @@ class PWMLED(PWMOutputDevice): LOW (the :meth:`off` method always does the opposite). :param bool initial_value: - If :data:`False` (the default), the LED will be off initially. If + If :data:`False` (the default), the LED will be off initially. If :data:`True`, the LED will be switched on initially. """ PWMLED.brightness = PWMLED.value @@ -548,7 +548,7 @@ class PWMLED(PWMOutputDevice): def LED(pin, pwm=True, active_high=True, initial_value=False): """ Returns an instance of :class:`DigitalLED` or :class:`PWMLED` depending on - the value of `pwm` parameter. + the value of the `pwm` parameter. :: @@ -573,7 +573,7 @@ def LED(pin, pwm=True, active_high=True, initial_value=False): LOW (the :meth:`off` method always does the opposite). :param bool initial_value: - If :data:`False` (the default), the device will be off initially. If + If :data:`False` (the default), the device will be off initially. If :data:`True`, the device will be switched on initially. """ if pwm: @@ -595,13 +595,13 @@ def LED(pin, pwm=True, active_high=True, initial_value=False): class PWMBuzzer(PWMOutputDevice): """ - Represents a passive buzzer driven by a PWM pin whose volume can be changed. + Represents a passive buzzer driven by a PWM pin; the volume of the buzzer can be changed. :param int pin: The pin that the buzzer is connected to. :param int freq: - The frequency of the PWM signal in Hertz. Defaults to 440. + The frequency of the PWM signal in hertz. Defaults to 440. :param int duty_factor: The duty factor of the PWM signal. This is a value between 0 and 65535. @@ -613,8 +613,8 @@ class PWMBuzzer(PWMOutputDevice): LOW (the :meth:`off` method always does the opposite). :param bool initial_value: - If :data:`False` (the default), the Buzzer will be off initially. If - :data:`True`, the Buzzer will be switched on initially. + If :data:`False` (the default), the buzzer will be off initially. If + :data:`True`, the buzzer will be switched on initially. """ def __init__(self, pin, freq=440, duty_factor=1023, active_high=True, initial_value=False): super().__init__(pin, freq, duty_factor, active_high, initial_value) @@ -630,7 +630,7 @@ class Speaker(OutputDevice, PinMixin): The pin that the speaker is connected to. :param int initial_freq: - The initial frequency of the PWM signal in Hertz. Defaults to 440. + The initial frequency of the PWM signal in hertz. Defaults to 440. :param int initial_volume: The initial volume of the PWM signal. This is a value between 0 and @@ -650,7 +650,7 @@ class Speaker(OutputDevice, PinMixin): 'a#1': 58, 'b1': 62, 'c2': 65, 'c#2': 69, 'd2': 73, 'd#2': 78, 'e2': 82, 'f2': 87, 'f#2': 93, 'g2': 98, 'g#2': 104, 'a2': 110, 'a#2': 117, 'b2': 123, 'c3': 131, 'c#3': 139, 'd3': 147, 'd#3': 156, 'e3': 165, 'f3': 175, 'f#3': 185, 'g3': 196, 'g#3': 208, 'a3': 220, 'a#3': 233, 'b3': 247, - 'c4': 262, 'c#4': 277, 'd4': 294, 'd#4': 311, 'e4': 330, 'f4': 349, 'f#4': 370, 'g4': 392, 'g#4': 415, 'a4': 440,'a#4': 466,'b4': 494, + 'c4': 262, 'c#4': 277, 'd4': 294, 'd#4': 311, 'e4': 330, 'f4': 349, 'f#4': 370, 'g4': 392, 'g#4': 415, 'a4': 440, 'a#4': 466, 'b4': 494, 'c5': 523, 'c#5': 554, 'd5': 587, 'd#5': 622, 'e5': 659, 'f5': 698, 'f#5': 740, 'g5': 784, 'g#5': 831, 'a5': 880, 'a#5': 932, 'b5': 988, 'c6': 1047, 'c#6': 1109, 'd6': 1175, 'd#6': 1245, 'e6': 1319, 'f6': 1397, 'f#6': 1480, 'g6': 1568, 'g#6': 1661, 'a6': 1760, 'a#6': 1865, 'b6': 1976, 'c7': 2093, 'c#7': 2217, 'd7': 2349, 'd#7': 2489, @@ -681,7 +681,7 @@ def off(self): @property def value(self): """ - Sets or returns the value of the speaker. value is a tuple of (freq, volume). + Sets or returns the value of the speaker. The value is a tuple of (freq, volume). """ return tuple(self.freq, self.volume) @@ -693,7 +693,7 @@ def value(self, value): @property def volume(self): """ - Sets or returns the volume of the speaker. 1 for max volume. 0 for off. + Sets or returns the volume of the speaker: 1 for maximum volume, 0 for off. """ return self._volume @@ -736,21 +736,21 @@ def _to_freq(self, freq): def beep(self, on_time=1, off_time=None, n=None, wait=False, fade_in_time=0, fade_out_time=None, fps=25): """ - Make the buzzer turn on and off repeatedly. + Makes the buzzer turn on and off repeatedly. :param float on_time: - The length of time in seconds the device will be on. Defaults to 1. + The length of time in seconds that the device will be on. Defaults to 1. :param float off_time: - The length of time in seconds the device will be off. If `None`, + The length of time in seconds that the device will be off. If `None`, it will be the same as ``on_time``. Defaults to `None`. :param int n: The number of times to repeat the beep operation. If `None`, the - device will continue blinking forever. The default is `None`. + device will continue beeping forever. The default is `None`. :param bool wait: - If True the method will block until the buzzer stops beeping. If False + If True, the method will block until the buzzer stops beeping. If False, the method will return and the buzzer will beep in the background. Defaults to False. @@ -773,51 +773,51 @@ def play(self, tune=440, duration=1, volume=1, n=1, wait=True): :param int tune: - The tune to play which can be specified as: + The tune to play can be specified as: + a single "note", represented as: + a frequency in Hz e.g. `440` + a midi note e.g. `60` - + a note name as a string e.g `"E4"` - + a list of note and duration e.g. `[440, 1]` or `["E4", 2]` - + a list of 2 value tuples of (note, duration) e.g. `[(440,1), (60, 2), ("e4", 3)]` + + a note name as a string e.g. `"E4"` + + a list of notes and duration e.g. `[440, 1]` or `["E4", 2]` + + a list of two value tuples of (note, duration) e.g. `[(440,1), (60, 2), ("e4", 3)]` Defaults to `440`. :param int volume: - The volume of the tune. 1 is max volume. 0 is mute. Defaults to 1. + The volume of the tune; 1 is maximum volume, 0 is mute. Defaults to 1. :param float duration: The duration of each note in seconds. Defaults to 1. :param int n: - The number of times to play the tune. If None the tune will play + The number of times to play the tune. If None, the tune will play forever. Defaults to 1. :param bool wait: - If True the method will block until the tune has finished. If False + If True, the method will block until the tune has finished. If False, the method will return and the tune will play in the background. Defaults to True. """ self.off() - # tune isnt a list, so it must be a single frequency or note + # tune isn't a list, so it must be a single frequency or note if not isinstance(tune, (list, tuple)): tune = [(tune, duration)] - # if the first element isnt a list, then it must be list of a single note and duration + # if the first element isn't a list, then it must be list of a single note and duration elif not isinstance(tune[0], (list, tuple)): tune = [tune] def tune_generator(): for note in tune: - # note isnt a list or tuple, it must be a single frequency or note + # note isn't a list or tuple, it must be a single frequency or note if not isinstance(note, (list, tuple)): # make it into a tuple note = (note, duration) - # turn the notes in frequencies + # turn the notes into frequencies freq = self._to_freq(note[0]) freq_duration = note[1] freq_volume = volume if freq is not None else 0 @@ -836,18 +836,18 @@ def close(self): class RGBLED(OutputDevice, PinsMixin): """ - Extends :class:`OutputDevice` and represents a full color LED component (composed + Extends :class:`OutputDevice` and represents a full colour LED component (composed of red, green, and blue LEDs). Connect the common cathode (longest leg) to a ground pin; connect each of the other legs (representing the red, green, and blue anodes) to any GP - pins. You should use three limiting resistors (one per anode). + pins. You should use three limiting resistors (one per anode). The following code will make the LED yellow:: from picozero import RGBLED rgb = RGBLED(1, 2, 3) rgb.color = (1, 1, 0) - 0-255 colours are also supported:: + 0–255 colours are also supported:: rgb.color = (255, 255, 0) @@ -892,11 +892,11 @@ def _write(self, value): @property def value(self): """ - Represents the color of the LED as an RGB 3-tuple of ``(red, green, + Represents the colour of the LED as an RGB 3-tuple of ``(red, green, blue)`` where each value is between 0 and 1 if *pwm* was :data:`True` - when the class was constructed (and only 0 or 1 if not). + when the class was constructed (but only takes values of 0 or 1 otherwise). For example, red would be ``(1, 0, 0)`` and yellow would be ``(1, 1, - 0)``, while orange would be ``(1, 0.5, 0)``. + 0)``, whereas orange would be ``(1, 0.5, 0)``. """ return tuple(led.value for led in self._leds) @@ -924,11 +924,11 @@ def _from_255(self, value): @property def color(self): """ - Represents the color of the LED as an RGB 3-tuple of ``(red, green, + Represents the colour of the LED as an RGB 3-tuple of ``(red, green, blue)`` where each value is between 0 and 255 if *pwm* was :data:`True` - when the class was constructed (and only 0 or 255 if not). + when the class was constructed (but only takes values of 0 or 255 otherwise). For example, red would be ``(255, 0, 0)`` and yellow would be ``(255, 255, - 0)``, while orange would be ``(255, 127, 0)``. + 0)``, whereas orange would be ``(255, 127, 0)``. """ return tuple(self._to_255(v) for v in self.value) @@ -939,8 +939,8 @@ def color(self, value): @property def red(self): """ - Represents the red component of the LED as value between 0 and 255 if *pwm* was :data:`True` - when the class was constructed (and only 0 or 255 if not). + Represents the red component of the LED as a value between 0 and 255 if *pwm* was :data:`True` + when the class was constructed (but only takes values of 0 or 255 otherwise). """ return self._to_255(self.value[0]) @@ -952,8 +952,8 @@ def red(self, value): @property def green(self): """ - Represents the green component of the LED as value between 0 and 255 if *pwm* was :data:`True` - when the class was constructed (and only 0 or 255 if not). + Represents the green component of the LED as a value between 0 and 255 if *pwm* was :data:`True` + when the class was constructed (but only takes values of 0 or 255 otherwise). """ return self._to_255(self.value[1]) @@ -965,8 +965,8 @@ def green(self, value): @property def blue(self): """ - Represents the blue component of the LED as value between 0 and 255 if *pwm* was :data:`True` - when the class was constructed (and only 0 or 255 if not). + Represents the blue component of the LED as a value between 0 and 255 if *pwm* was :data:`True` + when the class was constructed (but only takes values of 0 or 255 otherwise). """ return self._to_255(self.value[2]) @@ -977,25 +977,25 @@ def blue(self, value): def on(self): """ - Turn the LED on. This equivalent to setting the LED color to white + Turns the LED on. This is equivalent to setting the LED color to white, e.g. ``(1, 1, 1)``. """ self.value = (1, 1, 1) def invert(self): """ - Invert the state of the device. If the device is currently off + Inverts the state of the device. If the device is currently off (:attr:`value` is ``(0, 0, 0)``), this changes it to "fully" on - (:attr:`value` is ``(1, 1, 1)``). If the device has a specific color, - this method inverts the color. + (:attr:`value` is ``(1, 1, 1)``). If the device has a specific colour, + this method inverts the colour. """ r, g, b = self.value self.value = (1 - r, 1 - g, 1 - b) def toggle(self): """ - Toggle the state of the device. If the device has a specific colour then save that colour and turn off. - If the device is off, change it to the last colour or, if none, to fully on (:attr:`value` is ``(1, 1, 1)``). + Toggles the state of the device. If the device has a specific colour, then that colour is saved and the device is turned off. + If the device is off, it will be changed to the last colour it had when it was on or, if none, to fully on (:attr:`value` is ``(1, 1, 1)``). """ if self.value == (0, 0, 0): self.value = self._last or (1, 1, 1) @@ -1005,7 +1005,7 @@ def toggle(self): def blink(self, on_times=1, fade_times=0, colors=((1, 0, 0), (0, 1, 0), (0, 0, 1)), n=None, wait=False, fps=25): """ - Make the device blink between colours repeatedly. + Makes the device blink between colours repeatedly. :param float on_times: Single value or tuple of numbers of seconds to stay on each colour. Defaults to 1 second. @@ -1015,14 +1015,14 @@ def blink(self, on_times=1, fade_times=0, colors=((1, 0, 0), (0, 1, 0), (0, 0, 1 :type colors: tuple Tuple of colours to blink between, use ``(0, 0, 0)`` for off. :param colors: - The colors to blink between. Defaults to red, green, blue. + The colours to blink between. Defaults to red, green, blue. :type n: int or None :param n: Number of times to blink; :data:`None` (the default) means forever. :param bool wait: - If :data:`False` (the default), use a Timer to manage blinking - continue blinking and return immediately. If :data:`False`, only - return when the blink is finished (warning: the default value of + If :data:`False` (the default), use a Timer to manage blinking, + continue blinking, and return immediately. If :data:`False`, only + return when the blinking is finished (warning: the default value of *n* will result in this method never returning). """ self.off() @@ -1061,7 +1061,7 @@ def blink_generator(): def pulse(self, fade_times=1, colors=((0, 0, 0), (1, 0, 0), (0, 0, 0), (0, 1, 0), (0, 0, 0), (0, 0, 1)), n=None, wait=False, fps=25): """ - Make the device fade between colours repeatedly. + Makes the device fade between colours repeatedly. :param float fade_times: Single value or tuple of numbers of seconds to spend fading. Defaults to 1. @@ -1080,7 +1080,7 @@ def pulse(self, fade_times=1, colors=((0, 0, 0), (1, 0, 0), (0, 0, 0), (0, 1, 0) def cycle(self, fade_times=1, colors=((1, 0, 0), (0, 1, 0), (0, 0, 1)), n=None, wait=False, fps=25): """ - Make the device fade in and out repeatedly. + Makes the device fade in and out repeatedly. :param float fade_times: Single value or tuple of numbers of seconds to spend fading between colours. Defaults to 1. @@ -1106,7 +1106,7 @@ def close(self): class Motor(PinsMixin): """ - Represents a motor connected to a motor controller which has a 2 pin + Represents a motor connected to a motor controller that has a two-pin input. One pin drives the motor "forward", the other drives the motor "backward". @@ -1120,7 +1120,7 @@ class Motor(PinsMixin): :param bool pwm: If :data:`True` (the default), PWM pins are used to drive the motor. - When using PWM pins values between 0 and 1 can be used to set the + When using PWM pins, values between 0 and 1 can be used to set the speed. """ @@ -1134,17 +1134,17 @@ def on(self, speed=1, t=None, wait=False): Turns the motor on and makes it turn. :param float speed: - The speed as a value between -1 and 1. 1 turns the motor at - full speed direction, -1 turns the motor at full speed in + The speed as a value between -1 and 1: 1 turns the motor at + full speed in one direction, -1 turns the motor at full speed in the opposite direction. Defaults to 1. :param float t: - The time in seconds the motor should run for. If None is + The time in seconds that the motor should run for. If None is specified, the motor will stay on. The default is None. :param bool wait: - If True the method will block until the time `t` has expired. - If False the method will return and the motor will turn on in + If True, the method will block until the time `t` has expired. + If False, the method will return and the motor will turn on in the background. Defaults to False. Only effective if `t` is not None. """ @@ -1169,7 +1169,7 @@ def off(self): @property def value(self): """ - Sets or returns the motor speed as a value between -1 and 1. -1 is full + Sets or returns the motor speed as a value between -1 and 1: -1 is full speed "backward", 1 is full speed "forward", 0 is stopped. """ return self._forward.value + (-self._backward.value) @@ -1186,15 +1186,15 @@ def forward(self, speed=1, t=None, wait=False): Makes the motor turn "forward". :param float speed: - The speed as a value between 0 and 1. 1 is full speed. Defaults to 1. + The speed as a value between 0 and 1: 1 is full speed, 0 is stop. Defaults to 1. :param float t: - The time in seconds the motor should turn for. If None is + The time in seconds that the motor should turn for. If None is specified, the motor will stay on. The default is None. :param bool wait: - If True the method will block until the time `t` has expired. - If False the method will return and the motor will turn on in + If True, the method will block until the time `t` has expired. + If False, the method will return and the motor will turn on in the background. Defaults to False. Only effective if `t` is not None. """ @@ -1205,15 +1205,15 @@ def backward(self, speed=1, t=None, wait=False): Makes the motor turn "backward". :param float speed: - The speed as a value between 0 and 1. 1 is full speed. Defaults to 1. + The speed as a value between 0 and 1: 1 is full speed, 0 is stop. Defaults to 1. :param float t: - The time in seconds the motor should turn for. If None is + The time in seconds that the motor should turn for. If None is specified, the motor will stay on. The default is None. :param bool wait: - If True the method will block until the time `t` has expired. - If False the method will return and the motor will turn on in + If True, the method will block until the time `t` has expired. + If False, the method will return and the motor will turn on in the background. Defaults to False. Only effective if `t` is not None. """ @@ -1232,14 +1232,14 @@ def close(self): class Robot: """ - Represent a generic dual-motor robot / rover / buggy. + Represents a generic dual-motor robot / rover / buggy. - Alias for :class:`Rover` + Alias for :class:`Rover`. This class is constructed with two tuples representing the forward and - backward pins of the left and right controllers respectively. For example, + backward pins of the left and right controllers. For example, if the left motor's controller is connected to pins 12 and 13, while the - right motor's controller is connected to pins 14 and 15 then the following + right motor's controller is connected to pins 14 and 15, then the following example will drive the robot forward:: from picozero import Robot @@ -1253,10 +1253,10 @@ class Robot: :param tuple right: A tuple of two pins representing the forward and backward inputs of the - left motor's controller. + right motor's controller. :param bool pwm: - If :data:`True` (the default), pwm pins will be used, allowing ariable + If :data:`True` (the default), pwm pins will be used, allowing variable speed control. """ @@ -1297,16 +1297,16 @@ def forward(self, speed=1, t=None, wait=False): Makes the robot move "forward". :param float speed: - The speed as a value between 0 and 1. 1 is full speed. Defaults to 1. + The speed as a value between 0 and 1: 1 is full speed, 0 is stop. Defaults to 1. :param float t: - The time in seconds the robot should move for. If None is + The time in seconds that the robot should move for. If None is specified, the robot will continue to move until stopped. The default is None. :param bool wait: - If True the method will block until the time `t` has expired. - If False the method will return and the motor will turn on in + If True, the method will block until the time `t` has expired. + If False, the method will return and the motor will turn on in the background. Defaults to False. Only effective if `t` is not None. """ @@ -1318,16 +1318,16 @@ def backward(self, speed=1, t=None, wait=False): Makes the robot move "backward". :param float speed: - The speed as a value between 0 and 1. 1 is full speed. Defaults to 1. + The speed as a value between 0 and 1: 1 is full speed, 0 is stop. Defaults to 1. :param float t: - The time in seconds the robot should move for. If None is + The time in seconds that the robot should move for. If None is specified, the robot will continue to move until stopped. The default is None. :param bool wait: - If True the method will block until the time `t` has expired. - If False the method will return and the motor will turn on in + If True, the method will block until the time `t` has expired. + If False, the method will return and the motor will turn on in the background. Defaults to False. Only effective if `t` is not None. """ @@ -1340,16 +1340,16 @@ def left(self, speed=1, t=None, wait=False): right motor forward. :param float speed: - The speed as a value between 0 and 1. 1 is full speed. Defaults to 1. + The speed as a value between 0 and 1: 1 is full speed, 0 is stop. Defaults to 1. :param float t: - The time in seconds the robot should turn for. If None is + The time in seconds that the robot should turn for. If None is specified, the robot will continue to turn until stopped. The default is None. :param bool wait: - If True the method will block until the time `t` has expired. - If False the method will return and the motor will turn on in + If True, the method will block until the time `t` has expired. + If False, the method will return and the motor will turn on in the background. Defaults to False. Only effective if `t` is not None. """ @@ -1362,16 +1362,16 @@ def right(self, speed=1, t=None, wait=False): right motor backward. :param float speed: - The speed as a value between 0 and 1. 1 is full speed. Defaults to 1. + The speed as a value between 0 and 1: 1 is full speed, 0 is stop. Defaults to 1. :param float t: - The time in seconds the robot should turn for. If None is + The time in seconds that the robot should turn for. If None is specified, the robot will continue to turn until stopped. The default is None. :param bool wait: - If True the method will block until the time `t` has expired. - If False the method will return and the motor will turn on in + If True, the method will block until the time `t` has expired. + If False, the method will return and the motor will turn on in the background. Defaults to False. Only effective if `t` is not None. """ @@ -1502,7 +1502,7 @@ def value(self): class DigitalInputDevice(InputDevice, PinMixin): """ Represents a generic input device with digital functionality e.g. buttons - which can be either active or inactive. + that can be either active or inactive. :param int pin: The pin that the device is connected to. @@ -1520,7 +1520,8 @@ class DigitalInputDevice(InputDevice, PinMixin): The bounce time for the device. If set, the device will ignore any button presses that happen within the bounce time after a button release. This is useful to prevent accidental button - presses from registering as multiple presses. + presses from registering as multiple presses. The default is + :data:`None`. """ def __init__(self, pin, pull_up=False, active_state=None, bounce_time=None): super().__init__(active_state) @@ -1568,7 +1569,7 @@ def _pin_change(self, p): # re-enable the interupt p.irq(self._pin_change, Pin.IRQ_RISING | Pin.IRQ_FALLING) - # did the value actually changed? + # did the value actually change? if self._state != last_state: # set the state self._state = self._pin.value() @@ -1643,7 +1644,7 @@ def close(self): class Switch(DigitalInputDevice): """ - Represents a toggle switch which is either open or closed. + Represents a toggle switch, which is either open or closed. :param int pin: The pin that the device is connected to. @@ -1669,7 +1670,7 @@ def __init__(self, pin, pull_up=True, bounce_time=0.02): class Button(Switch): """ - Represents a push button which can be either pressed or released. + Represents a push button, which can be either pressed or released. :param int pin: The pin that the device is connected to. @@ -1694,8 +1695,8 @@ class Button(Switch): class AnalogInputDevice(InputDevice, PinMixin): """ - Represents a generic input device with analogy functionality e.g. - a potentiometer + Represents a generic input device with analogue functionality, e.g. + a potentiometer. :param int pin: The pin that the device is connected to. @@ -1703,9 +1704,9 @@ class AnalogInputDevice(InputDevice, PinMixin): :param active_state: The active state of the device. If :data:`True` (the default), the :class:`AnalogInputDevice` will assume that the device is - active when the pin is high and above the threshold . If + active when the pin is high and above the threshold. If ``active_state`` is ``False``, the device will be active when - the pin is is low and below the threshold. + the pin is low and below the threshold. :param float threshold: The threshold that the device must be above or below to be @@ -1749,7 +1750,7 @@ def is_active(self): @property def voltage(self): """ - Returns the voltage of the analog device. + Returns the voltage of the analogue device. """ return self.value * 3.3 @@ -1758,7 +1759,7 @@ def close(self): class Potentiometer(AnalogInputDevice): """ - Represents a Potentiometer which outputs with a variable voltage + Represents a potentiometer, which outputs a variable voltage between 0 and 3.3V. Alias for :class:`Pot`. @@ -1769,9 +1770,9 @@ class Potentiometer(AnalogInputDevice): :param active_state: The active state of the device. If :data:`True` (the default), the :class:`AnalogInputDevice` will assume that the device is - active when the pin is high and above the threshold . If + active when the pin is high and above the threshold. If ``active_state`` is ``False``, the device will be active when - the pin is is low and below the threshold. + the pin is low and below the threshold. :param float threshold: The threshold that the device must be above or below to be @@ -1788,7 +1789,7 @@ def pico_temp_conversion(voltage): class TemperatureSensor(AnalogInputDevice): """ - Represents a TemperatureSensor which outputs a variable voltage. The voltage + Represents a TemperatureSensor, which outputs a variable voltage. The voltage can be converted to a temperature using a `conversion` function passed as a parameter. @@ -1800,9 +1801,9 @@ class TemperatureSensor(AnalogInputDevice): :param active_state: The active state of the device. If :data:`True` (the default), the :class:`AnalogInputDevice` will assume that the device is - active when the pin is high and above the threshold . If + active when the pin is high and above the threshold. If ``active_state`` is ``False``, the device will be active when - the pin is is low and below the threshold. + the pin is low and below the threshold. :param float threshold: The threshold that the device must be above or below to be @@ -1840,7 +1841,7 @@ def temp(self): @property def conversion(self): """ - Set or returns the conversion function for the device. + Sets or returns the conversion function for the device. """ return self._conversion @@ -1857,10 +1858,10 @@ class DistanceSensor(PinsMixin): Represents a HC-SR04 ultrasonic distance sensor. :param int echo: - The pin which the ECHO pin is connected to. + The pin that the ECHO pin is connected to. :param int trigger: - The pin which the TRIG pin is connected to. + The pin that the TRIG pin is connected to. :param float max_distance: The :attr:`value` attribute reports a normalized value between 0 (too @@ -1884,9 +1885,9 @@ def _read(self): sleep(0.00001) self._trigger.off() - # if an echo isnt measured in 100 milliseconds, it should - # be considered out of range the maximum length of the - # echo is 38 milliseconds but its not known how long the + # If an echo isn't measured in 100 milliseconds, it should + # be considered out of range. The maximum length of the + # echo is 38 milliseconds but it's not known how long the # transmission takes after the trigger stop = ticks_ms() + 100 while echo_off is None and not timed_out: @@ -1911,7 +1912,7 @@ def value(self): the sensor or is sufficiently near that the sensor can’t tell the difference, and 1, indicating the reflector is at or beyond the specified max_distance. A return value of None indicates that the - echo was not received before the time out. + echo was not received before the timeout. """ distance = self.distance return distance / self._max_distance if distance is not None else None