|
Digital pin 11 is one of these PWM pins. If the LED module is plugged into the Arduino, the blue pin of the LED module is in digital pin 11 of the Arduino.
But there's one other complicating factor we have to take care of to make this work. The joystick value ranges from 0 to 1023. But the range of values for a PWM pin, like digital pin 11, is only 0 to 255. So we have to take the value we get from the joystick and convert it to a brightness value the PWM pin can use. If the joystick value is the max value of 1023, then it needs to be converted to 255, the max value the PWM pin can take. If the joystick value is 0, then the PWM value will be 0. And similarly for all the values in between. The conversion formula needed is a proportional equation: \(brightnessvalue = (joystickvalue)(\frac{255}{1023})\) We can check the formula to make sure it works. For example, if the joystickvalue is 1023, we see that the brightnessvalue will be 255. And if the joystick value is 0, the brightnessvalue will be 0. It's also good to check the midpoint value of the range. Using integer values only, the midpoint of 0 to 1023 is 512. Putting that value into the equation gives a brightnessvalue of 127, which is the midpoint of 0 to 255.
|

| Grid Size: S M L | Simple View: | MinView: |
| Coord: x-axis y-axis | Grid Lines: x-axis y-axis | |||
| Grid: | 12x12 inches | 24x24 inches | 36x36 inches | |
| 72x72 inches | 96x96 inches | 192x192 inches | ||
| 1x1 inches | 2x2 inches | Fraction: | ||
| xy-Range: | ||||
|
|
||||
|
|
||||
| Quad: | 1 Quadrant | 4 Quadrants | 1&4 Quadrants | |
| Units: | US Customary | Metric | Ruler: | |
| Labels: |
|
|
|
|
Font
px
|
|
| Tics Lines: |
|
Width
px
|
| Hash Lines: |
|
Width
px
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
(
,
in
) in
|
|
degrees
|
|
|
|
Set up the Arduino with LED and joystick and then click the Run button. Move the joystick forward and backward to slide the brightness of the blue LED up and down. Press the joystick button to end. Once it's working, add a print block to the loop code that will print the brightness value during each iteration. (You may also want to change the delay value from 0.1 seconds to 0.5 seconds. Note also that, depending on the calibration of the joystick, the midpoint value of the joystick may be slightly different from 128, the midpoint of the range from 0 to 255.) |
|
|
|||||||||||
|
|||||||||||
