Skip to content

Commit 02daf32

Browse files
authored
Merge branch 'dev' into feature/TouchSensor
2 parents 2e8dc7d + 1261466 commit 02daf32

File tree

7 files changed

+137
-294
lines changed

7 files changed

+137
-294
lines changed

docs/examples/stepper.py

Lines changed: 0 additions & 129 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from picozero import Stepper
2+
3+
# Second Hand Clock - Continuous 60s Rotation
4+
# One full revolution every 60 seconds.
5+
6+
STEP_DELAY = 60.0 / 2048 # ≈ 0.029296875 seconds per step (full-step)
7+
8+
stepper = Stepper((1, 2, 3, 4), step_delay=STEP_DELAY)
9+
10+
stepper.run_continuous(direction="cw")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from picozero import Stepper
2+
from time import localtime, sleep
3+
4+
stepper = Stepper((1, 2, 3, 4), step_sequence="half")
5+
6+
OPEN_TIME = (7, 0) # Open at 7:00 AM (hour, minute)
7+
CLOSE_TIME = (20, 0) # Close at 8:00 PM
8+
ROTATIONS = 5 # Number of full rotations needed to fully open/close blinds
9+
10+
# Track state
11+
is_open = False
12+
13+
14+
def open_blinds():
15+
global is_open
16+
if not is_open:
17+
for _ in range(ROTATIONS):
18+
stepper.rotate(1, "cw")
19+
is_open = True
20+
21+
22+
def close_blinds():
23+
global is_open
24+
if is_open:
25+
for _ in range(ROTATIONS):
26+
stepper.rotate(1, "ccw")
27+
is_open = False
28+
29+
30+
def check_schedule():
31+
now = localtime()
32+
current_time = (now.tm_hour, now.tm_min)
33+
34+
# Check if it's time to open
35+
if current_time == OPEN_TIME and not is_open:
36+
open_blinds()
37+
38+
# Check if it's time to close
39+
elif current_time == CLOSE_TIME and is_open:
40+
close_blinds()
41+
42+
43+
# Set starting position (closed)
44+
stepper.reset_position()
45+
is_open = False
46+
47+
# Check every 30 seconds
48+
while True:
49+
check_schedule()
50+
sleep(30)

docs/examples/stepper_positioning.py

Lines changed: 0 additions & 121 deletions
This file was deleted.

docs/recipes.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,18 @@ Move the rover (roughly) in a square:
287287

288288
.. literalinclude:: examples/robot_rover_square.py
289289

290+
290291
Stepper motor
291292
-------------
292293

293-
Control a stepper motor connected via a driver board (e.g. ULN2003):
294+
Control a stepper motor connected via a driver board (e.g. ULN2003) to create:
294295

295-
.. literalinclude:: examples/stepper.py
296+
Analog clock (continuous second hand):
297+
.. literalinclude:: examples/stepper_analog_clock.py
296298

297-
Advanced positioning with precise angle control:
299+
Automatic blinds (multi-rotation, time-based):
300+
.. literalinclude:: examples/stepper_automatic_blinds.py
298301

299-
.. literalinclude:: examples/stepper_positioning.py
300302

301303
Internal temperature sensor
302304
---------------------------

0 commit comments

Comments
 (0)