title | layout | meta-description | share | author | about | cats | simple-description | date | date-updated |
---|---|---|---|---|---|---|---|---|---|
Potentiometer and the Microbit |
text-width-sidebar |
Examples of using the potentiometer and the microbit. |
true |
jez |
Examples of using a Potentiometer with the microbit. |
component examples |
Potentiometer Examples |
2016-12-23 10:20:00 UTC |
2016-12-23 10:20:00 UTC |
All examples use a simple 10k potentiometer.
See the component article on this website about the LED.
{:.ui .header .dividing}
Dim and LED based on the reading/rotation of the potentiometer.
- LED
- 220Ω resistor
- 10kΩ potentiometer
pot = pin1 led = pin0
while True: led.write_analog(pot.read_analog()) sleep(100) {% endhighlight %}
This should work a lot better than it does.
The LED flickers each time write_analog()
is called. Hopefully someone has a solution.
{% highlight javascript %} let potReading = 0
basic.forever(() => { potReading = pins.analogReadPin(AnalogPin.P1) pins.analogWritePin(AnalogPin.P0, potReading) })
{% endhighlight %}
{:.ui .header .dividing}
Mix colours based on the reading from three potentiometers.
- RGB LED
- 3 × 220Ω resistors
- 3 × 10kΩ potentiometer
- microbit breakout board
{% highlight python %} from microbit import *
red_pot = pin0 green_pot = pin1 blue_pot = pin2
red_led = pin10 green_led = pin3 blue_led = pin4
while True: # get colors from pots # returned values range from 0 - 1023 red = red_pot.analog_read() green = green_pot.analog_read() blue = blue_pot.analog_read()
# write colours to LEDs
red_led.analog_write(red)
green_led.analog_write(green)
red_led.analog_write(blue)
sleep(100)
{% endhighlight %}