Skip to content

Commit 63ac38c

Browse files
Apply suggestions from code review
Co-authored-by: Renat0Ribeir0 <[email protected]>
1 parent f04c9d7 commit 63ac38c

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

content/Hardware Support/Generic/Use-PWM-output-with-Arduino.md

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,12 @@ void loop() {
3232

3333
## Change the PWM resolution
3434

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.
3636

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).
3838

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
47-
48-
// Set PWM resolution to 12 bits
49-
analogWriteResolution(12);
50-
analogWrite(12, map(sensorVal, 0, 1023, 0, 4095));
51-
52-
// 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.
5741
5842
---
5943

0 commit comments

Comments
 (0)