Back to Activity
Tutorial
Servo control
{% trans 'Sorry, your browser does not support canvas -- please either update your browser or submit your requirements by phone or email.' %}

Accelerometer

Loading Blockly...

Step 1 /5

Introduction

Servos are precise motors that you can make rotate in predictable ways.

Step 2 /5

Setting up servo outputs

  • First click on the blue cog on the start block and tick the checkbox next to extension pins input/output.

  • Click the cog again to close this window.

  • Select digital output from the leg 6 as dropdown menu on the start block.

This puts leg 6 into the servo output mode.

Step 3 /5

Looping

  • Now from the Loops menu, drag in a repeat while true loop and snap it below your start block, so you can repeatedly move the servo back and forth.

Step 4 /5

Moving the servo

  • From the Servo menu, drag in two set servo blocks and snap them inside your repeat while true loop.

  • From the Basics menu, drag in two pause blocks and snap one below each of your set servo blocks.

  • Click on the leg number of your set servo blocks and change them to 6.

  • Click on the number block inside the position block of your first set servo block and change the number to 0.

  • Click on the number block inside the position block of your second set servo block and change the number to 255.

This will code will move the servo one way, wait a second and move the servo back again. It will repeat this again and again.

Step 5 /5

Download your code

  • Download your code and load it onto your CodeBug.