1- #!/usr/bin/env python3
2-
31from gpiozero import Servo
42from time import sleep
53
64# Hardware Configuration
7- SERVO0_PIN = 12
8- SERVO1_PIN = 13
5+ # Updated to include the new GPIO 19
6+ PINS = [12 , 13 , 19 ]
7+ servos = []
98
10- # Initialize Servos
11- # We use a standard pulse width range (min=1ms, max=2ms)
12- servo0 = Servo (SERVO0_PIN )
13- servo1 = Servo (SERVO1_PIN )
9+ print ("--- KIDA Triple Servo Initialization ---" )
1410
15- def test_sweep (servo_obj , name ):
16- print (f"--- Testing { name } ---" )
17-
18- print ("Moving to MIN position..." )
19- servo_obj .min ()
20- sleep (1 )
21-
22- print ("Moving to MID position..." )
23- servo_obj .mid ()
24- sleep (1 )
25-
26- print ("Moving to MAX position..." )
27- servo_obj .max ()
28- sleep (1 )
29-
30- print ("Returning to MID..." )
31- servo_obj .mid ()
32- sleep (0.5 )
11+ for pin in PINS :
12+ try :
13+ servos .append (Servo (pin ))
14+ print (f"✅ Servo initialized on GPIO { pin } " )
15+ except Exception as e :
16+ print (f"❌ Failed to initialize GPIO { pin } : { e } " )
3317
34- try :
35- print ("Starting Servo Test..." )
36- test_sweep (servo0 , "Servo 0 (Pin 12)" )
37- test_sweep (servo1 , "Servo 1 (Pin 13)" )
38- print ("Test Complete!" )
18+ def sweep_test ():
19+ try :
20+ while True :
21+ for i , s in enumerate (servos ):
22+ pin_num = PINS [i ]
23+ print (f"\n Testing Servo on Pin { pin_num } " )
24+
25+ print (" Moving to MIN..." )
26+ s .min ()
27+ sleep (0.8 )
28+
29+ print (" Moving to MAX..." )
30+ s .max ()
31+ sleep (0.8 )
32+
33+ print (" Centering..." )
34+ s .mid ()
35+ sleep (0.5 )
36+
37+ print ("\n --- Cycle Complete. Restarting in 2s... ---" )
38+ sleep (2 )
3939
4040except KeyboardInterrupt :
41- print ("\n Test stopped by user." )
42-
41+ print ("\n Stopping tests..." )
4342finally :
44- # Cleanup
45- servo0 .value = None
46- servo1 .value = None
43+ # Release the pins
44+ for s in servos :
45+ s .value = None
46+ print ("Cleanup complete." )
47+
48+ if __name__ == "__main__" :
49+ sweep_test ()
0 commit comments