Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have added another example in micropython for controlling the Servo with Potentiometer #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions controlwithpot.py
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions examples/Sweep/Sweep.py
Original file line number Diff line number Diff line change
@@ -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)