#define LED_PIN_A4 A4 // Define the pin for the first LED
#define LED_PIN_A5 A5 // Define the pin for the second LED
int brightnessA4 = 0; // Current brightness level for LED A4
int brightnessA5 = 255; // Current brightness level for LED A5 (starting from fully on)
int fadeAmount = 5; // How much to change the brightness
void setup() {
pinMode(LED_PIN_A4, OUTPUT); // Set the A4 LED pin as an output
pinMode(LED_PIN_A5, OUTPUT); // Set the A5 LED pin as an output
}
void loop() {
// Fade in for LED on A4 and fade out for LED on A5
for (brightnessA4 = 0; brightnessA4 <= 255; brightnessA4 += fadeAmount) {
analogWrite(LED_PIN_A4, brightnessA4); // Set the brightness of the LED on A4
analogWrite(LED_PIN_A5, brightnessA5); // Set the brightness of the LED on A5
brightnessA5 -= fadeAmount; // Decrease brightness for A5
delay(30); // Wait for 30 milliseconds
}
// Fade out for LED on A4 and fade in for LED on A5
for (brightnessA4 = 255; brightnessA4 >= 0; brightnessA4 -= fadeAmount) {
analogWrite(LED_PIN_A4, brightnessA4); // Set the brightness of the LED on A4
analogWrite(LED_PIN_A5, brightnessA5); // Set the brightness of the LED on A5
brightnessA5 += fadeAmount; // Increase brightness for A5
delay(30); // Wait for 30 milliseconds
}
}
Loading
st-nucleo-c031c6
st-nucleo-c031c6