๐
ADC โ Analog to Digital
The real world is analog โ temperature, voltage, pressure all vary continuously. The RP2040's 12-bit ADC samples these voltages and converts them to integers 0โ4095. adc_read() returns this number in microseconds.
12-bit = 4096 steps
๐
PWM โ Pulse Width Modulation
GPIO pins are either ON (3.3V) or OFF (0V) โ they can't output 1.65V directly. PWM switches the pin on and off very fast. If it's ON 50% of the time, the LED sees an average of 1.65V and appears half-bright.
Duty cycle = brightness
๐
The Control Loop
adc_read() โ divide by 64 โ that's the brightness value. Then gpio_put(LED,1), sleep_us(brightness), gpio_put(LED,0), sleep_us(1000-brightness). Higher ADC = longer ON time = brighter LED.
pot_value / 64