Created
December 10, 2016 18:30
-
-
Save raster/1e053ef5dc9825e05d7c2419c3449340 to your computer and use it in GitHub Desktop.
Get comma separated values returned from a function
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 | |
void setup() { | |
Serial.begin(9600); | |
randomSeed(analogRead(A0)); | |
} | |
void loop() { | |
char* rgb = returnColors(); | |
int r, g, b; | |
if (sscanf(rgb, "%d,%d,%d", &r, &g, &b) == 3) { | |
Serial.print(r); | |
Serial.print(", "); | |
Serial.print(g); | |
Serial.print(", "); | |
Serial.println(b); | |
} | |
delay(500); | |
} | |
char* returnColors() { | |
char* myColors[6]; | |
myColors[0] = "128,0,0"; | |
myColors[1] = "0,128,0"; | |
myColors[2] = "0,0,128"; | |
myColors[3] = "255,0,0"; | |
myColors[4] = "0,255,0"; | |
myColors[5] = "0,0,255"; | |
int colorIndex = random(0,6); | |
char* result = myColors[colorIndex]; | |
return (result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment