import time import threading from http.server import BaseHTTPRequestHandler, HTTPServer import RPi.GPIO as GPIO # ================= GPIO SETUP ================= GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) OUT1, OUT2, OUT3, OUT4 = 12, 11, 13, 15 PINS = [OUT1, OUT2, OUT3, OUT4] for p in PINS: GPIO.setup(p, GPIO.OUT) GPIO.output(p, GPIO.LOW) # ================= MOTOR SEQUENCE (same as motor_test) ================= SEQ_HALF = [ (1,0,0,0), (1,0,1,0), (0,0,1,0), (0,1,1,0), (0,1,0,0), (0,1,0,1), (0,0,0,1), (1,0,0,1), ] STEP_DELAY = 0.01 STEPS_90 = 100 motor_lock = threading.Lock() def set_coils(s): GPIO.output(OUT1, GPIO.HIGH if s[0] else GPIO.LOW) GPIO.output(OUT2, GPIO.HIGH if s[1] else GPIO.LOW) GPIO.output(OUT3, GPIO.HIGH if s[2] else GPIO.LOW) GPIO.output(OUT4, GPIO.HIGH if s[3] else GPIO.LOW) def step_motor_halfsteps(halfsteps, direction=+1): """ direction=+1 forward: SEQ_HALF[i % 8] direction=-1 reverse: SEQ_HALF[(-i) % 8] Exactly matches motor_test behavior. """ for i in range(halfsteps): idx = (i % 8) if direction > 0 else ((-i) % 8) set_coils(SEQ_HALF[idx]) time.sleep(STEP_DELAY) # for p in PINS: # GPIO.output(p, GPIO.LOW) # ================= WEB PAGE ================= HTML = f"""
90° = {STEPS_90} half-steps