You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/Hardware Support/Generic/Use-PWM-output-with-Arduino.md
+4-20Lines changed: 4 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,28 +32,12 @@ void loop() {
32
32
33
33
## Change the PWM resolution
34
34
35
-
You can modify the resolution of PWM signals using the `analogWriteResolution()` function. By default, the resolution is 8 bits, meaning values passed to `analogWrite()`can range between 0-255, which ensures backward compatibility with AVR-based boards.
35
+
Depending on your board's core, you can modify the resolution of PWM signals using the [`analogWriteResolution()`](https://docs.arduino.cc/language-reference/en/functions/analog-io/analogWriteResolution/) function. By default, the resolution is 8 bits, meaning that values passed to the `analogWrite()`function range between 0 and 255, which ensures backward compatibility with AVR-based boards.
36
36
37
-
To change the resolution, use `analogWriteResolution(bits)`, where `bits` determines the resolution in bits, ranging from 1 to 32. If the resolution set is higher than your board’s capabilities, extra bits will be discarded. If it's lower than your board’s capabilities, the missing bits will be padded with zeros
37
+
To change the resolution, use `analogWriteResolution(bits)`, where `bits` determines the resolution in bits, ranging from 1 to 32. [See an example code](https://docs.arduino.cc/language-reference/en/functions/analog-io/analogWriteResolution/#example-code).
38
38
39
-
```arduino
40
-
void setup() {
41
-
Serial.begin(9600);
42
-
pinMode(11, OUTPUT);
43
-
}
44
-
45
-
void loop() {
46
-
int sensorVal = analogRead(A0); // Read the analog input from A0
// Print the mapped 12-bit PWM value to the serial monitor
53
-
Serial.print("12-bit PWM value: ");
54
-
Serial.print(map(sensorVal, 0, 1023, 0, 4095));
55
-
}
56
-
```
39
+
> [!NOTE]
40
+
> If the resolution set is higher than your board’s capabilities, the extra bits will be discarded. If it's lower than your board’s capabilities, the missing bits will be padded with zeros.
0 commit comments