#include <Streaming.h>
Print &cout {Serial};
// 000 off
// 100 red
// 010 green
// 001 blue
// 011 cyan
// 110 yellow
// 101 magenta
// 111 white
// uint32_t -> 00000000 111 101 110 011 001 010 100 000
constexpr uint8_t RGB_LED_PINS[] {A1, A2, A3};
enum ColorNum {off, red, green, blue, cyan, yellow, magenta, white};
template <size_t N> void setRGBLed(const uint8_t (&pin)[N], uint8_t colorNum) {
uint32_t colorBits {0b00000000111101110011001010100000};
uint8_t colors = (colorBits >> (colorNum * 3)) & 0b111;
// cout << _WIDTHZ(_BIN(colors), 32) << endl;
// cout << _WIDTHZ(_BIN(mask), 32) << endl;
for (size_t i {0}; i < N; ++i) { digitalWrite(pin[i], colors << i & 0b100); }
}
void setup() {
Serial.begin(115200);
for (auto &p : RGB_LED_PINS) { pinMode(p, OUTPUT); }
randomSeed(analogRead(A0));
}
void loop() {
uint8_t colorNr = random(1,8);
setRGBLed(RGB_LED_PINS, colorNr);
delay(400);
}