Analog Out Serial Sketch, Arduino for Dummies, Page 116 (MVI 8025)

Опубликовано: 16 Июль 2026
на канале: Stephen Campbell
189
0

Analog Out Serial Sketch, Arduino for Dummies, Page 116.
The variable resistor reading is used to control the brightness of the LED. Output pin 9 which is a PWM (Pulse Width Modulation) pin is used to control the brightness of the LED. PWM is the method of high speed switching off and on to provide the appearance of a variable current. The Arduino (Atmel ATMega 328PU chip) provides some pins that are PWM enabled, the chip handling the switching so the program only has to provide a number symbolic ie 0 to 255. 0 equals off and 255 equals bright.
The range of the LED is 0 to 255 but the variable resistor is 0 to 1023.
The C function 'map' is used to return a value from 0 to 255 when reading a value from 0 to 1023. This is basically a percentage conversion ie. 50% of 0 to 1023 is 600, 50% of 0 to 255 is around 127.