2.RGB-LED-Chaser
This is an example of the ShiftRegisterOut class of the Control Surface library. It creates light effects using three 8-bit shift registers and some RGB LEDs .
Boards: AVR, AVR USB, Nano Every, Nano 33 IoT, Nano 33 BLE, Due, Teensy 3.x, ESP8266, ESP32
Connections
Connect three daisy-chained shift registers to the SPI pins.
Connect 8 RGB LEDs (+ current limiting resistors) to the outputs of the shift registers.
SCK >───────────┬──────────────────────┬──────────────────────┐
┏━━━━━━━┷━━━━━━━┓ ┏━━━━━━━┷━━━━━━━┓ ┏━━━━━━━┷━━━━━━━┓
┃ SH_CP ┃ ┃ SH_CP ┃ ┃ SH_CP ┃
MOSI >───┨ DS Q7S ┠──────┨ DS Q7S ┠──────┨ DS Q7S ┃
┃ ST_CP ┃ ┃ ST_CP ┃ ┃ ST_CP ┃
┗━━━━━━━┯━━━━━━━┛ ┗━━━━━━━┯━━━━━━━┛ ┗━━━━━━━┯━━━━━━━┛
SS >───────────┴──────────────────────┴──────────────────────┘
Remember to connect the enable pin of the shift register to ground and the master reset pin to Vcc in order to enable it.
The order of the colors doesn't matter. You can change them in software using the ShiftRegisterOutRGB::redBit
, ShiftRegisterOutRGB::greenBit
and ShiftRegisterOutRGB::blueBit
constants.
If you wired the LEDs as RGB (red first, then green and then blue), the red bit is 0, the green bit is 1 and the blue bit is 2.
If you wired the LEDs as BGR (blue first, then green and then red), the red bit is 2, the green bit is 1 and the blue bit is 0.
Other combinations are possible as well.
Behavior
This example will turn on all red LEDs one by one, then turn them off one by one, next, it will turn on and off all green LEDs in the same manner, and finally the same for the blue LEDs . This is repeated indefinitely.
Demo
VIDEO
Written by Pieter P, 2018-07-13
https://github.com/tttapa/Arduino-Helpers
void setup() {
}
constexpr unsigned long delayTime = 50;
void loop() {
for (uint8_t i = 0; i < 8; i++) {
delay(delayTime);
}
for (uint8_t i = 0; i < 8; i++) {
delay(delayTime);
}
for (uint8_t i = 0; i < 8; i++) {
delay(delayTime);
}
for (uint8_t i = 0; i < 8; i++) {
delay(delayTime);
}
for (uint8_t i = 0; i < 8; i++) {
delay(delayTime);
}
for (uint8_t i = 0; i < 8; i++) {
delay(delayTime);
}
}
constexpr PinStatus_t LOW
constexpr PinStatus_t HIGH
Dummy header file for Arduino builder.
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
void begin() override
Initialize the shift register.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.
A namespace with alternatives to the standard Arduino IO functions that can be used with extended IO ...
static const uint8_t redBit
The position of the red output pin for 3-color LEDs.
static const uint8_t blueBit
The position of the blue output pin for 3-color LEDs.
static const uint8_t greenBit
The position of the green output pin for 3-color LEDs.