10 years, 6 months ago.

how to use a function in a main program ?

Hello, As the title says, I just want to know , how I can use a function that I just created in my main program. Thank you

1 Answer

10 years, 6 months ago.

Previously you posted the code below.

On line 12 you create a function. On line 30 you call that function from your main program.

You are asking how to do something that you have already done.

#include "mbed.h"
#include "TextLCD.h"
 
InterruptIn in(p10);
Timer t;
Timer t_on;
Timer t_off;
TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
 
// la fonction qui va retourner le dwell
 
int fonction_dwell(alpha)
{
    int d;
    d=alpha*100;
    return d;
    }
int main()
{
    float alpha;
    int calcul;
    int dwell;
    if (in==1) {  // <--- the input that you have created not the pin number.
    t_on.start();
    t_off.stop();
  } else {
    t_on.stop();
    t_off.start();
    alpha=t_on/(t_on+t_off);
    calcul=fonction_dwell(alpha);
  }  
    
     while (1) {
       
        lcd.printf("\n %d dwell\r\n",calcul);    
}
    
    }