Enter Data Using a Rotary Knob Device (Rotary Encoder)
Used in Digital Radios
as a Volume Control.
Wire Up the Micro:bit
Used in Robot Vacuum as shown.
Cleaners to measure The Wire’s Colour Isn’t
Distance Travelled. Important.
Both Direction and Distance Travelled can be Measured
using this device:
Distance:
• Count the number of Pulses. 1 Pulse is :
Light passes through the Slots Direction:
in the Disc to produce a Pulse • If Pulse A occurs Before Pulse B or Visa Versa.
as it Breaks the Light Beam.
Turning Clockwise
Turning Anti-Clockwise
Enter Data Using a Rotary Knob Device (Rotary Encoder)
Create Wait Here until
All This the First Edge of
Pulse A occurs.
Code
Initialise the
Micro:bit’s
Pins used and
the variable
Counter.
Detect when Pulse B Occurs to determine If the Knob’s Switch is
which Direction the Knob is Rotating. Pressed then Reset the
variable Counter to 5.
Observe:
• The display only Counts Up or Down Cor-
rectly if the Knob is Rotated Very Slowly.
Reason:
• The Show Number takes a Long Time to
execute, so the Micro:bit may Miss Some
Wait until Pulse A
of the Pulses.
has completed.
Solution:
• Use the Serial Write Number as opposed
to Show Number to display the numbers i.e. Wait for it to
on the PC ‘s Screen instead. go Low Again