Refactoring for Pete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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