Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ Speaker
:inherited-members:
:members:

Motor
-----

.. autoclass:: Motor
:show-inheritance:
:inherited-members:
:members:

Robot
-----

.. autoclass:: Robot
:show-inheritance:
:inherited-members:
:members:

DigitalOutputDevice
-------------------
Expand Down Expand Up @@ -103,6 +118,14 @@ TemperatureSensor
:inherited-members:
:members:

DistanceSensor
--------------

.. autoclass:: DistanceSensor
:show-inheritance:
:inherited-members:
:members:

DigitalInputDevice
------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/examples/motor_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from picozero import Motor
from time import sleep

motor = Motor(14, 15)

motor.move()
sleep(1)
motor.stop()
9 changes: 9 additions & 0 deletions docs/examples/robot_rover_forward.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from picozero import Robot
from time import sleep

robot_rover = Robot(left=(14,15), right=(12,13))

# move forward
robot_rover.forward()
sleep(1)
robot_rover.stop()
10 changes: 10 additions & 0 deletions docs/examples/robot_rover_square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from picozero import Robot
from time import sleep

robot_rover = Robot(left=(14,15), right=(12,13))

for i in range(4):
# move forward for 1 second
robot_rover.forward(t=1, wait=True)
# rotate to the left for 1 second
robot_rover.left(t=1, wait=True)
4 changes: 2 additions & 2 deletions docs/examples/ultrasonic_distance_sensor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from picozero import DistanceSensor
from time import sleep

ds = DistanceSensor(echo=5, trigger=4)
ds = DistanceSensor(echo=4, trigger=5)

while True:
print(ds.distance)
sleep(0.1)
sleep(0.1)
817 changes: 817 additions & 0 deletions docs/images/distance_sensor_bb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8,150 changes: 8,150 additions & 0 deletions docs/images/robot_bb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 27 additions & 2 deletions docs/recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ Print the value, voltage and percent reported by a potentiometer:

In the Thonny Python editor, choose View->Plotter to plot the output of :meth:`print`.


Buzzer
------

Expand All @@ -169,6 +168,29 @@ Control a passive buzzer or speaker that can play different tones or frequencies

.. literalinclude:: examples/speaker.py

Motor
-----

Move a motor which is connected via 2 pins (forward / backward) and a motor controller board

.. literalinclude:: examples/motor_move.py

Robot rover
-------------

Make a simple 2 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

Move the rover forward for 1 second and stop.

.. literalinclude:: examples/robot_rover_forward.py

Move the rover *roughly* in a square:

.. literalinclude:: examples/robot_rover_square.py

Play a tune
~~~~~~~~~~~

Expand All @@ -193,6 +215,9 @@ Check the internal temperature of the Raspberry Pi Pico in degrees Celcius:
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

.. literalinclude:: examples/ultrasonic_distance_sensor.py
Binary file added docs/sketches/distance_sensor.fzz
Binary file not shown.
File renamed without changes.
Binary file added docs/sketches/robot.fzz
Binary file not shown.
14 changes: 14 additions & 0 deletions examples/motor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from picozero import Motor
from time import sleep

m = Motor(12, 13)

# turn the motor for 1 second
print("the motor is turning")
m.move()
sleep(1)
m.stop()

# or alternatively turn it at half speed for 2 seconds
m.move(speed=0.5, t=2)
print("the motor will turn at half speed and stop after 2 seconds")
2 changes: 2 additions & 0 deletions picozero/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
Speaker,

RGBLED,
Motor,
Robot,

DigitalInputDevice,
Switch,
Expand Down
Loading