Hi guys, apologies if this is in the wrong place,
I'm starting my first Arduino project and as part of the prep work I'm trying to find the best way to handle RGB information and colour transitions for an LED. My script so far is:
#define RED 11
#define GREEN 10
#define BLUE 9
int Colours[21][3] = {
{150,100,70}, // White 0
{200,0,0}, // Red 1
{201,9,0}, // Maroon 2
{189,18,0}, // Ember 3
{177,27,0}, // Orange 4
{190,24,6}, // Salmon 5
{180,81,1}, // Straw 6
{105,81,0}, // Honeycombe 7
{100,100,6}, // Aqua 8
{21,172,9}, // Grass 9
{0,200,0}, // Green 10
{0,105,21}, // Swamp 11
{36,150,60}, // Teal 12
{50,139,150}, // Crystal 13
{30,60,186}, // Cyan 14
{0,0,200}, // Blue 15
{90,3,186}, // Purple 16
{120,0,126}, // Lilac 17
{163,1,24}, // Pink 18
{99,15,69}, // Soft 19
{186,36,54} // Pastel 20
};
int Row = 0;
int R;
int G;
int B;
int Static() {
if(Row == 20) { Row = 0; }
else { Row += 1; }
}
void setup() {
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
}
void loop() {
Static();
R = Colours[Row][0];
G = Colours[Row][1];
B = Colours[Row][2];
analogWrite(RED,R);
analogWrite(GREEN,G);
analogWrite(BLUE,B);
delay(750);
}
This allows the LED to scroll through the colours in the multi-dimensional array. The thing is, it only works if I have the Row variable as global and I would prefer it to be nested within the function (without making explicit references to the RGB values within the function) so that different LEDs can behave according to different functions at the same time. Similarly, I'd like the delay to be nested within the function rather than in the loop. How might I go about this?