Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Refactoring for Pete
// RandomColor.ino
struct RGB
{
uint8_t r;
uint8_t g;
uint8_t b;
};
RGB palette[] PROGMEM =
{
{128, 0, 0 },
{0, 128, 0 },
{0, 0, 128 },
{255, 0, 0 },
{0, 255, 0 },
{0, 0, 255 }
};
uint16_t palette_count;
void setup() {
Serial.begin(9600);
randomSeed(analogRead(A0));
palette_count = sizeof(palette) / sizeof(RGB);
}
void loop() {
uint16_t rgb_index = random(0, palette_count);
Serial.print(palette[rgb_index].r);
Serial.print(", ");
Serial.print(palette[rgb_index].g);
Serial.print(", ");
Serial.println(palette[rgb_index].b);
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment