Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Servo Position Control with Python and micro:bit

Servo Position Control with Python and micro:bit

Solutions

Questions

  1. Answer: Servo motors can be used to control things such as: motorized theatre props, car windows, motorized furniture, blinds, and hydraulic car jacks.
  2. Answer: The direction the horn angle points.
  3. Answer: Angular velocity is how fast the horn turns when it’s moving from one position to another, so when it is constant it is the change in angle over time.
  4. Answer: positive

 

Exercises

  1. Answer: Approximately 26 and 128 respectively.
  2. Answer: 90°
  3. Answer: Angular velocity ω = (Θf – Θi) / t
    ω = (135° – 45°)/1.5 s
    ω = 90°/1.5 s
    ω = 60°/ s
  4. Answer: Angular velocity ω = (Θf – Θi) / t
    ω = (45° – 180°)/2.3 s
    ω = -135°/2.3 s
    ω ≈ -58.7°/ s

 

Projects

1. Solution: This script is written for the range of 0° to 45°. Any 45° span is acceptable.

from microbit import *

display.off()
pin9.set_pull(pin9.NO_PULL)
pin6.set_pull(pin6.NO_PULL)
pin16.set_analog_period(20)

value = 77

while True:
    state9 = pin9.read_digital()
    state6 = pin6.read_digital()

    if state9 is 1:
        value = value + 1
        if value > 51:
            value = 51
    if state6 is 1:
        value = value - 1
        if value < 26:
            value = 26
    
    pin16.write_analog(value)
    sleep(20)

 

2. Solution:

from microbit import *

display.off()
pin9.set_pull(pin9.NO_PULL)
pin6.set_pull(pin6.NO_PULL)
pin16.set_analog_period(20)

value = 77

while True:
    state9 = pin9.read_digital()
    state6 = pin6.read_digital()

    if state9 is 1:
        value = value + 1
        if value > 128:
            value = 128
    if state6 is 1:
        value = value - 2
        if value < 26:
            value = 26
    
    pin16.write_analog(value)
    sleep(20)


Printer-friendly version
Review and Practice
Prev
Tilt Servo Control
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress