Fades the green LED (D1) in and out with PWM while the red LED (D2) does the opposite, so one brightens as the other dims. One full cycle, in and out, takes about 2 s.
- Jumpers
- JP3 at 3.3 V.
- Output
- The LEDs only; nothing is printed.
- Notes
- Both LEDs are active low: the anode goes to VDD and the pin sinks the current, so a lower analogWrite() value gives a brighter LED. setBrightness() writes 255 - brightness, so 0 is off and 255 is full brightness.
constexpr uint32_t STEP_MS = 4;
void setBrightness(uint8_t pin, uint8_t brightness) {
analogWrite(pin, 255 - brightness);
}
void setup() {
}
void loop() {
for (int brightness = 0; brightness <= 255; ++brightness) {
setBrightness(
LED1, brightness);
setBrightness(
LED2, 255 - brightness);
delay(STEP_MS);
}
for (int brightness = 255; brightness >= 0; --brightness) {
setBrightness(
LED1, brightness);
setBrightness(
LED2, 255 - brightness);
delay(STEP_MS);
}
}
Library for the U of T Physics Analog Shield (Introduction to Electronics).
Encoder, switch, temperature signals, potentiometer and LEDs on the Analog Shield.
Definition AnalogShield.h:64
void begin()
Sets pin modes, turns both LEDs off and starts tracking the encoder and its switch.
Definition AnalogShield.cpp:56
Shield signals by Arduino pin, from the Rev-C schematic.
Definition AnalogShield.h:26
constexpr uint8_t LED1
D1 green LED, active low (anode to VDD).
Definition AnalogShield.h:44
constexpr uint8_t LED2
D2 red LED, active low (anode to VDD).
Definition AnalogShield.h:43