Introduction
You might have already played with an LED and gotten it to blink using the micro:bit.Â
In this guide, you will be introduced to the potentiometer and program it using MakeCode and on the Arduino IDE to change an LED's brightness.Â
Once you have finished this guide, you will know how to use potentiometers with the micro:bit. You will make an LED light dimmer with it! Potentiometer can be used for all sorts of projects, from volume control to MIDI, just to name a few examples.
-
-
-
-
-
-
-
-
-
-
let full_angle = 0 let vcc = 0 vcc = 3.3 full_angle = 300
-
let brightness = 0 let degrees = 0 let voltage = 0 let full_angle = 0 let sensorVal = 0 let vcc = 0 vcc = 3.3 full_angle = 300 basic.forever(function () { sensorVal = pins.analogReadPin(AnalogPin.P0) voltage = Math.idiv(sensorVal * vcc, 1023) degrees = Math.idiv(voltage * full_angle, vcc) brightness = Math.map(degrees, 0, full_angle, 0, 255) pins.analogWritePin(AnalogPin.P2, brightness) basic.pause(500) })
-