Format Trinket Gemma Servo Control
MODIFY
Trinket_Gemma_Servo_Control/Trinket_Gemma_Servo_Control.py
Trinket_Gemma_Servo_Control/Trinket_Gemma_Servo_Control.py
-import time
import board
-from analogio import AnalogIn
import simpleio
+from analogio import AnalogIn
# servo pin for the M0 boards:
servo = simpleio.Servo(board.A2)
@@ -10,19 +9,21 @@ angle = 0
# potentiometer
trimpot = AnalogIn(board.A1) # pot pin for servo control
-def remapRange(value, leftMin, leftMax, rightMin, rightMax):
+
+def remap_range(value, left_min, left_max, right_min, right_max):
# this remaps a value from original (left) range to new (right) range
# Figure out how 'wide' each range is
- leftSpan = leftMax - leftMin
- rightSpan = rightMax - rightMin
+ left_span = left_max - left_min
+ right_span = right_max - right_min
# Convert the left range into a 0-1 range (int)
- valueScaled = int(value - leftMin) / int(leftSpan)
+ value_scaled = int(value - left_min) / int(left_span)
# Convert the 0-1 range into a value in the right range.
- return int(rightMin + (valueScaled * rightSpan))
+ return int(right_min + (value_scaled * right_span))
+
while True:
- angle = remapRange(trimpot.value, 0, 65535, 0, 180)
+ angle = remap_range(trimpot.value, 0, 65535, 0, 180)
servo.angle = angle
# time.sleep(0.05)

Format Trinket Gemma Servo Control