Come up with a project.
Pin is high is called Pulse width - half the total time it takes to go from low to high to low again.
*Arduino boards have a few pins which can generate a continuous PWM signal. On the Arduino Nano 33 IoT. They’re pins 2, 3, 5, 6, 9, 10, 11, 12, A2, A3, and A5.
1 | analogWrite(pin, duty); |
---|
LED Dimming - The simplest application of analogWrite() is to change the brightness of an LED.
DC Motor Speed Control - the speed of a DC motor using the analogWrite() command as well.
Servomotors (伺服馬達)- control the movement of something. Motors with a combination of gears and an embedded potentiometer (variable resistor) that allows you to set their position fairly precisely within a 180-degree range.
Changing Frequency
If want to generate a changing tone on an Arduino microcontroller, however, there is a tone() command that will do this for you:
1 | tone(pin, frequency); |
---|
Ranges of Values