Trick of using userDefined_Function() in Arduino - Yash Vidyasagar

Trick of using userDefined_Function() in Arduino

Such types of functions are called as User Defined Functions (UDFs). They are NOT the default functions of Arduino. The userDefined_Function() function can be used in the program as follows:

The Code

int LED0=0; 
int LED1=1; 
int LED2=2; 
int LED3=3; 
int LED4=4; 
int LED5=5; 
int LED6=6; 
int LED7=7; 

void allLEDs_ON()
{
digitalWrite(LED0, HIGH);   
digitalWrite(LED1, HIGH); 
digitalWrite(LED2, HIGH);   
digitalWrite(LED3, HIGH); 
digitalWrite(LED4, HIGH);   
digitalWrite(LED5, HIGH); 
digitalWrite(LED6, HIGH);   
digitalWrite(LED7, HIGH);   
}

void allLEDs_OFF()
{
digitalWrite(LED0, LOW);    
digitalWrite(LED1, LOW); 
digitalWrite(LED2, LOW);    
digitalWrite(LED3, LOW); 
digitalWrite(LED4, LOW);    
digitalWrite(LED5, LOW); 
digitalWrite(LED6, LOW);    
digitalWrite(LED7, LOW);    
}

void setup() 
{
pinMode(LED0, OUTPUT);   
pinMode(LED1, OUTPUT);   
pinMode(LED2, OUTPUT); 
pinMode(LED3, OUTPUT);   
pinMode(LED4, OUTPUT);   
pinMode(LED5, OUTPUT); 
pinMode(LED6, OUTPUT);   
pinMode(LED7, OUTPUT); 
}

void loop() // infinite loop 
  {
allLEDs_ON();
delay(1000); 

  allLEDs_OFF()
delay(1000); 
  }


Note:Though the use of user defined functions is good, but still its boring. If we have to use the UDF many times in a program, then UDFs are recommended. But if you want to use the UDF only once, in the program, then this trick is still boring…!

Leave a Reply