Skip to content

Instantly share code, notes, and snippets.

@roycepipkins
Last active December 10, 2016 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roycepipkins/c9160cdd8b3e0d3d87831eb454cce017 to your computer and use it in GitHub Desktop.
Save roycepipkins/c9160cdd8b3e0d3d87831eb454cce017 to your computer and use it in GitHub Desktop.
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