Skip to content

Commit 71a4bae

Browse files
committed
2 parents f59f8c9 + 1c686da commit 71a4bae

3 files changed

Lines changed: 47 additions & 34 deletions

File tree

DRV8825/DRV8825/Examples/drv8825-acceleration.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
# LAST UPDATED: 2025-05-27
55

66
from drv8825 import DRV8825 # Import the DRV8825 motor driver module
7-
from time import sleep # Import sleep function for timing delays
7+
from time import sleep # Import sleep function for timing delays
88

99
# Define GPIO pins for motor control
10-
DIR_PIN = 4 # GPIO pin used for direction control
10+
DIR_PIN = 4 # GPIO pin used for direction control
1111
STEP_PIN = 5 # GPIO pin used for step pulses
1212

1313
# Create a DRV8825 motor instance
@@ -33,14 +33,16 @@
3333
# Gradually increase the step frequency (i.e., speed up the motor)
3434
accelerationFactor = 1
3535
while accelerationFactor < 2000:
36-
motor.step() # Send a single step pulse to the motor
37-
sleep(1 / accelerationFactor) # Delay inversely proportional to the factor (higher = faster)
38-
accelerationFactor += 1 # Increase acceleration factor
39-
print(accelerationFactor) # Print current acceleration factor
36+
motor.step() # Send a single step pulse to the motor
37+
sleep(
38+
1 / accelerationFactor
39+
) # Delay inversely proportional to the factor (higher = faster)
40+
accelerationFactor += 1 # Increase acceleration factor
41+
print(accelerationFactor) # Print current acceleration factor
4042

4143
# Gradually decrease the step frequency (i.e., slow down the motor)
4244
while accelerationFactor > 1:
43-
motor.step() # Send a single step pulse
44-
sleep(1 / accelerationFactor) # Delay increases as acceleration factor decreases
45-
accelerationFactor -= 1 # Decrease acceleration factor
46-
print(accelerationFactor) # Print current acceleration factor
45+
motor.step() # Send a single step pulse
46+
sleep(1 / accelerationFactor) # Delay increases as acceleration factor decreases
47+
accelerationFactor -= 1 # Decrease acceleration factor
48+
print(accelerationFactor) # Print current acceleration factor

WS2812/WS2812/Examples/ws2812b-blink.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,30 @@
33
# BRIEF: A simple example of blinking WS2812b LED's
44
# LAST UPDATED: 2025-05-26
55

6-
import machine # For accessing GPIO pins
7-
import neopixel # Library to control WS2812b (NeoPixel) LEDs
8-
import time # For delay/sleep functions
6+
import machine # For accessing GPIO pins
7+
import neopixel # Library to control WS2812b (NeoPixel) LEDs
8+
import time # For delay/sleep functions
99

1010
# === Configuration ===
11-
PIN = 33 # GPIO pin connected to the data line of the WS2812B LED strip
12-
NUM_PIXELS = 24 # Number of LEDs in the strip (adjust this to match your setup)
11+
PIN = 33 # GPIO pin connected to the data line of the WS2812B LED strip
12+
NUM_PIXELS = 24 # Number of LEDs in the strip (adjust this to match your setup)
1313

1414
# === Setup ===
1515
# Create a NeoPixel object on the specified GPIO pin with the specified number of LEDs
1616
np = neopixel.NeoPixel(machine.Pin(PIN), NUM_PIXELS)
1717

18+
1819
# === Function to set all LEDs to a specified color (R, G, B) ===
1920
def set_color(r, g, b):
2021
for i in range(NUM_PIXELS): # Iterate over each LED
21-
np[i] = (r, g, b) # Set the color for the current LED
22-
np.write() # Update the strip (could be moved outside loop for efficiency)
22+
np[i] = (r, g, b) # Set the color for the current LED
23+
np.write() # Update the strip (could be moved outside loop for efficiency)
2324

2425

2526
# === Blink loop ===
2627
# Continuously blink all LEDs on and off
2728
while True:
28-
set_color(255, 255, 255) # Turn all LEDs on to full white
29-
time.sleep(0.5) # Wait 0.5 seconds
30-
set_color(0, 0, 0) # Turn all LEDs off (black)
31-
time.sleep(0.5) # Wait 0.5 seconds
32-
33-
29+
set_color(255, 255, 255) # Turn all LEDs on to full white
30+
time.sleep(0.5) # Wait 0.5 seconds
31+
set_color(0, 0, 0) # Turn all LEDs off (black)
32+
time.sleep(0.5) # Wait 0.5 seconds

WS2812/WS2812/Examples/ws2812b-simple-fade.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# BRIEF: A simple fade animation on WS2812b LED's
44
# LAST UPDATED: 2025-05-26
55

6-
import machine # For accessing hardware like GPIO
7-
import neopixel # NeoPixel/WS2812B control module
8-
import time # For delays
6+
import machine # For accessing hardware like GPIO
7+
import neopixel # NeoPixel/WS2812B control module
8+
import time # For delays
99

1010
# === Configuration ===
11-
PIN = 33 # GPIO pin connected to the data line of the WS2812B strip
12-
NUM_PIXELS = 24 # Number of LEDs in the strip (adjust to your setup)
11+
PIN = 33 # GPIO pin connected to the data line of the WS2812B strip
12+
NUM_PIXELS = 24 # Number of LEDs in the strip (adjust to your setup)
1313

1414
# === Setup ===
1515
# Initialize NeoPixel object on the specified pin with the given number of LEDs
@@ -18,15 +18,27 @@
1818
# === Fade Loop ===
1919
# This loop creates a moving red gradient (fading tail) along the LED strip
2020
while True:
21-
for j in range(NUM_PIXELS): # Outer loop: shift the animation forward one LED at a time
22-
time.sleep(0.01) # Short delay to control overall speed
23-
for i in range(NUM_PIXELS): # Inner loop: calculate and set brightness for each LED
24-
time.sleep(0.01) # Additional delay for smoother visual effect
21+
for j in range(
22+
NUM_PIXELS
23+
): # Outer loop: shift the animation forward one LED at a time
24+
time.sleep(0.01) # Short delay to control overall speed
25+
for i in range(
26+
NUM_PIXELS
27+
): # Inner loop: calculate and set brightness for each LED
28+
time.sleep(0.01) # Additional delay for smoother visual effect
2529

2630
# Calculate LED index based on current position (j) and brightness position (i)
2731
if j + i < NUM_PIXELS:
28-
np[i + j] = (i * 8, 0, 0) # Set red intensity based on position (i), green and blue = 0
32+
np[i + j] = (
33+
i * 8,
34+
0,
35+
0,
36+
) # Set red intensity based on position (i), green and blue = 0
2937
else:
30-
np[(i + j) - NUM_PIXELS] = (i * 8, 0, 0) # Wrap around when index exceeds strip length
38+
np[(i + j) - NUM_PIXELS] = (
39+
i * 8,
40+
0,
41+
0,
42+
) # Wrap around when index exceeds strip length
3143

3244
np.write() # Update the LED strip with new values

0 commit comments

Comments
 (0)