diff --git a/controlwithpot.py b/controlwithpot.py new file mode 100644 index 0000000..be2c562 --- /dev/null +++ b/controlwithpot.py @@ -0,0 +1,22 @@ +#This is a micropython example for controlling the servo with a potentiometer. +#Potentiometer is referred as pot here. +#Please connect the pot with pin 0 +#Please connect the pot with pin 1 + +import machine +import pyb +import time + +pot = machine.ADC(0) +servo = pyb.Servo(1) + + +#Map function similar to the one in arduino +def map(value, range1_lb, range1_ub, range2_lb, range2_ub): + return ((value - range1_lb) * (range2_ub - range2_lb) / (range1_ub - range1_lb) + range2_lb ) + +while(True): + value = pot.read() + value = int(map(value, 0, 1024, -90, 90)) + servo.angle(value, 1000) + time.sleep(1) \ No newline at end of file diff --git a/examples/Sweep/Sweep.py b/examples/Sweep/Sweep.py new file mode 100644 index 0000000..2a0c949 --- /dev/null +++ b/examples/Sweep/Sweep.py @@ -0,0 +1,17 @@ +#Sweep of Servo +# Using the Servo +# Make sure you have the Servo checkbox marked! + +import machine +import pyb +import time + +# The pyboard has four simple servo connections +servo = pyb.Servo(1) +while(1): + for x in range(-90,91): + servo.angle(x, 5000) + time.sleep_ms(15) + for x in range(90,-91, -1): + servo.angle(x, 5000) + time.sleep_ms(15) \ No newline at end of file