Knob (potentiometer)
A potentiometer has three legs. The two outer legs go to + and −; the middle leg gives a voltage between them, depending on where you turn the knob.
Middle leg to an analog pin: the program reads 0 (turned fully one way) to 1023 (fully the other way).
More: reading it, and map
An analog pin measures a voltage instead of only on and off. map turns the number 0 to 1023 into any range you need, for example 0 to 359 for a colour on the colour wheel, or 0 to 180 for a servo angle.
The same in Python
def on_forever(): led.plot_bar_graph(pins.analog_read_pin(AnalogPin.P2), 1023) basic.forever(on_forever)
On the Micro:bit, pins 0, 1 and 2 can read analog values.
void setup() { Serial.begin(9600); } void loop() { int value = analogRead(A0); // 0 to 1023 int angle = map(value, 0, 1023, 0, 180); // into 0 to 180 Serial.println(angle); // see it in the Serial Monitor delay(100); }