FUNCTION POINTER IN ARDUINO

 


FUNCTION POINTER

In this tutorial we are going to see function pointer.

A function pointer is used to points the starting point of a  function.

The function pointer must have same type of arguments as original function.

CODE

void fun();
void (*ptr[0])();
void setup() {
  Serial.begin(9600);
}
void loop() {
 ptr[0]=fun;
 ptr[0]();
 delay(700);
}
void fun()
{
  Serial.println("EMBSYSTRONIX.BLOGSPOT.COM");
  Serial.println();
}

CODE EXPLANATION
In the above code, a function void fun() is created
An array of pointer function is created
void (*ptr[0])();

void setup()

In void setup function serial communication is enabled with baud rate of 9600 bits per second.

void loop()
In void loop function., the ptr[0] index stores the begining addess of a function fun;
then the pointer ptr[0](); is called and it calls the fun() and it prints 
"EMBSYSTRONIX.BLOGSPOT.COM" repeatedly for 700 ms time delay.




Comments