Control LED brightness, buzzers, and motor driver speed inputs.
Open in compiler →/*
Roboda verified Arduino sample 0429
Feature: PWM Fade
Generated for online build, classroom practice, and hardware upload testing.
*/
const byte pwmPin = 11;
int level = 0;
int stepSize = 9;
void setup() {
pinMode(pwmPin, OUTPUT);
}
void loop() {
analogWrite(pwmPin, level);
level += stepSize;
if (level <= 0 || level >= 255) {
stepSize = -stepSize;
}
delay(51);
}
How it works
Create a smooth analog-like output using PWM.
- Use a PWM-capable pin from the map.
- Connect an LED with resistor or a motor driver enable input.
- Increase level until it reaches 255.
- Reverse stepSize to fade back down.
Connections
| Pin | Connect to | Note |
|---|---|---|
| D11 | LED through resistor or motor-driver enable input | Must be a PWM-capable pin for analogWrite(). |