#define TRUE 1
#define FALSE 0
const int numLEDs=4;
const int GPIO_Pins[]={1,3,8,12}; //store all pin number in the array
const int blinkRate = 500; // in milliseconds
static bool flag = TRUE; // cannot be const as it has to toggle between true and false
void setup() {
// put your setup code here, to run once:
//int led ; variable name can be called anything
for(int led=0;led<numLEDs;led++)
{
pinMode(GPIO_Pins[led],OUTPUT);
//ARRAY at index LED is initalised in the for loop with each iteration
}
}
void loop() {
// put your main code here, to run repeatedly:
//initially FLAG is TRUE
for(int led=0;led<numLEDs;led++)
{
//user defined function
controlLEDs(led,flag); //function call
}
delay(blinkRate);//500 milli seconds delay
flag = !flag; //FLAG = FALSE (inversion of previous reading)
//goes back to the beginning on loop() function and the for loop starts from 0 again
}
void controlLEDs(int led,bool state)
{
if(state==TRUE)
digitalWrite(GPIO_Pins[led],HIGH);
else
digitalWrite(GPIO_Pins[led],LOW);
}