Ameba Arduino: [RTL8195AM] [RTL8710AF] PWM - Let LED to fade and light in turn
- Breadboard x 1
- Ameba x 1
- LED x 1
- 1 KΩ Resistor x 1
In this example, we use the PWM component to fade and light the LED in turn. A PWM component uses digital signal to simulate analog signal. By adjusting the duration of 3V3 and 0V, PWM produces the average voltage output with different value.
For example, in the figure below, as the proportion of 3v3 in a duration drops, the average voltage output decreases:
Therefore, we use the varying of average voltage output of PWM to make the LED to fade and light alternately.
Open the sample code in “File” -> “Examples” -> “01. Basics” -> “Fade”:
In this example, we use pin D9. Please refer to the wiring diagram:
Below is the RTL8710 Wiring Diagram:
Afterwards, upload the sample code and press the reset button. Then you can see the LED fades and lights alternately.
And the documentation of PWM on the Arduino website:
In Setup, we use pinMode(pin, mode) to set D9 to output mode:
and use analogWrite(pin, value) to set output frequency (0~255):