initial commit
|
|
@ -0,0 +1 @@
|
|||
/files/
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
import board
|
||||
import pwmio
|
||||
import time
|
||||
|
||||
motorIN1 = pwmio.PWMOut(board.GP8, frequency=1000, duty_cycle=0)
|
||||
motorIN2 = pwmio.PWMOut(board.GP9, frequency=1000, duty_cycle=0)
|
||||
|
||||
|
||||
# DRIVE FORWARD
|
||||
motorIN1.duty_cycle = 65535 # This is the maximum value
|
||||
motorIN2.duty_cycle = 0 # This is the minimum value
|
||||
time.sleep(1)
|
||||
|
||||
# DRIVE BACKWARD
|
||||
motorIN1.duty_cycle = 0
|
||||
motorIN2.duty_cycle = 65535
|
||||
time.sleep(1)
|
||||
|
||||
# STOP
|
||||
motorIN1.duty_cycle = 0
|
||||
motorIN2.duty_cycle = 0
|
||||
|
||||
|
||||
|
||||
|
||||
import board
|
||||
import pwmio
|
||||
import time
|
||||
|
||||
# Initialize motor PWM pins
|
||||
motorIN1 = pwmio.PWMOut(board.GP8, frequency=1000, duty_cycle=0)
|
||||
motorIN2 = pwmio.PWMOut(board.GP9, frequency=1000, duty_cycle=0)
|
||||
|
||||
def motor(power):
|
||||
# Make sure power is never greater than 100 or less than -100
|
||||
if power > 100:
|
||||
power = 100
|
||||
elif power < -100:
|
||||
power = -100
|
||||
|
||||
# Convert 0-100 value, to 0 to 65535
|
||||
duty = abs(power) * 65535 // 100
|
||||
|
||||
# Apply power to a motor pin, depending on if its greater or less than 0
|
||||
if power > 0:
|
||||
motorIN1.duty_cycle = duty
|
||||
motorIN2.duty_cycle = 0
|
||||
elif power < 0:
|
||||
motorIN1.duty_cycle = 0
|
||||
motorIN2.duty_cycle = duty
|
||||
else:
|
||||
motorIN1.duty_cycle = 0
|
||||
motorIN2.duty_cycle = 0
|
||||
|
||||
# TESTS
|
||||
motor(100) # FULL FORWARD
|
||||
time.sleep(3)
|
||||
motor(-100) # FULL REVERSE
|
||||
time.sleep(3)
|
||||
|
||||
# Start at FULL REVERSE and slowly change from -100 to 100
|
||||
for i in range(-100, 100):
|
||||
motor(i)
|
||||
print(i)
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import board
|
||||
import time
|
||||
import motor
|
||||
|
||||
left_motor = motor.Motor(board.GP8, board.GP9)
|
||||
|
||||
# TESTS
|
||||
left_motor.move(100) # FULL FORWARD
|
||||
time.sleep(2)
|
||||
left_motor.move(-100) # FULL REVERSE
|
||||
time.sleep(2)
|
||||
left_motor.move(0)
|
||||
|
||||
# Start at FULL REVERSE and slowly change from -100 to 100
|
||||
for i in range(-100, 100):
|
||||
left_motor.move(i)
|
||||
print(i)
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
|
||||
import pwmio
|
||||
|
||||
class Motor:
|
||||
def __init__(self, in1_pin, in2_pin, frequency=1000):
|
||||
# Set up PWM outputs on the specified pins
|
||||
self.in1 = pwmio.PWMOut(in1_pin, frequency=frequency, duty_cycle=0)
|
||||
self.in2 = pwmio.PWMOut(in2_pin, frequency=frequency, duty_cycle=0)
|
||||
|
||||
def move(self, power):
|
||||
# Constrain power to -100 to 100
|
||||
if power > 100:
|
||||
power = 100
|
||||
elif power < -100:
|
||||
power = -100
|
||||
|
||||
# Scale to duty cycle
|
||||
duty = abs(power) * 65535 // 100
|
||||
|
||||
if power > 0:
|
||||
self.in1.duty_cycle = duty
|
||||
self.in2.duty_cycle = 0
|
||||
elif power < 0:
|
||||
self.in1.duty_cycle = 0
|
||||
self.in2.duty_cycle = duty
|
||||
else:
|
||||
self.in1.duty_cycle = 0
|
||||
self.in2.duty_cycle = 0
|
||||
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 199 KiB |
|
After Width: | Height: | Size: 374 KiB |
|
After Width: | Height: | Size: 3.8 MiB |
|
After Width: | Height: | Size: 608 KiB |
|
After Width: | Height: | Size: 209 KiB |
|
After Width: | Height: | Size: 115 KiB |
|
After Width: | Height: | Size: 739 KiB |
|
After Width: | Height: | Size: 368 KiB |
|
After Width: | Height: | Size: 141 KiB |
|
After Width: | Height: | Size: 407 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 502 KiB |
|
|
@ -0,0 +1,45 @@
|
|||
/* styles.css */
|
||||
h2 {
|
||||
font-weight: 800 !important;
|
||||
/* Bold */
|
||||
font-size: 1.2rem;
|
||||
/* Slightly larger than default */
|
||||
margin-bottom: 0.5rem;
|
||||
/* Optional: space below */
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-weight: 600 !important;
|
||||
/* Bold */
|
||||
font-size: 1.1rem;
|
||||
/* Slightly larger than default */
|
||||
margin-bottom: 0.5rem;
|
||||
/* Optional: space below */
|
||||
}
|
||||
|
||||
code {
|
||||
color: rgb(0, 178, 0);
|
||||
}
|
||||
|
||||
|
||||
/* Optional: underline active tab */
|
||||
.tab-btn.active {
|
||||
border-bottom: 2px solid #2563eb;
|
||||
/* Tailwind blue-600 */
|
||||
color: #2563eb;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #2563eb !important; /* Tailwind blue-600 hex */
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
ol li {
|
||||
line-height: 2;
|
||||
padding-left: 0.5rem; /* ensures indentation */
|
||||
}
|
||||