Turn a potentiometer to move a servo, mapping the reading from 0 to 180 degrees.
This tutorial is part of the Nairda learning path. You can build it step by step inside the app, which checks every block you place before letting you move on.
The steps
- We add a While loop, which repeats forever.
- We declare a servo on pin 9.
- We declare a potentiometer called pot on analog pin 0.
- We create a number variable called reading.
- Inside the loop we put a delay of 100 milliseconds.
- Behind it we set reading to a Map block.
- What we map is the pot reading.
- The pot comes in from 0 to 100 and goes out from 0 to 180 degrees.
- Behind it we put the servo and give it the variable reading.
When you finish, the app takes you straight to the next tutorial in the path.