Fonction et sous fonction

Bonjour,

Voici mon problème :

Je souhaite dans une fonction, inclure une sous fonction. J'ai lu et relu pas mal d'articles sur le sujet mais je ne m'en sors pas.

Voici le bout de code incriminé :

void affichEclPPSec() {
  tft.changeMode(TEXT); tft.setFontScale(1); tft.setTextColor(RA8875_WHITE, RA8875_BLACK);
  tft.setCursor(0, 70); tft.print("Eclairage PP");
  x = 202; void *rectVert();
  tft.setTextColor(RA8875_WHITE, RA8875_BLACK);
  tft.setCursor(275, 70); tft.print(" Second."); tft.changeMode(GRAPHIC);
  tft.drawRect(410, 68, 50, 40, couleurRect1); tft.setCursor(419, 70); tft.print("NO");
}


void *rectVert() {
  tft.changeMode(GRAPHIC);
  tft.drawRect(x, 68, 50, 40, couleurRect); tft.setCursor(x+9, 70); tft.print("OK");
  tft.changeMode(TEXT); 
}

Le code complet compile mais la sous fonction "rectVert" est ignorée car le rectangle vert et ok n'apparaissent pas sur l'écran.

Merci de m'aider

Que fait cette ligne ?

  x = 202; void *rectVert();

Si elle doit appeler rectVertOK, il faut écrire :
  x = 202; rectVertOK();et ôter l'étoile devant le nom de ta fonction plus bas :

void rectVertOK() {

Bonjour,

@lesept

Désolé pour le retard à répondre. J'ai édité le #1 car le OK était en trop dans la sous fonction rectVert.

J'avais écrit au début ce que tu me proposes ça compile mais ça ne fonctionne pas.

J'ai lu qu'on ne pouvait pas appeler une fonction à l'intérieur d'une autre fonction, il faut passer par un système de pointeur mais je n'arrive pas à comprendre la mécanique de fonctionnement.

D'ou la présence des * dans le code joint.

merci pour l'aide

EGT59:
J'ai lu qu'on ne pouvait pas appeler une fonction à l'intérieur d'une autre fonction, il faut passer par un système de pointeur mais je n'arrive pas à comprendre la mécanique de fonctionnement.

Bonjour,

Bien sur que si, on peut appeler une fonction à l'intérieur d'une fonction (heureusement).
Ce qu'on ne peut pas c'est définir une fonction à l'intérieur d'une fonction.

Ok mais ce que je comprends pas c'est pourquoi ma fonction rectVert fonctionne si je l'appelle dans la loop mais ne fonctionne pas si je l"appelle dans la fonction affichEclPPSec ?

Sans le code complet impossible de répondre.

Voici le code complet, c'est le code d'essais pour la mise en page de l'écran :

#include <Wire.h>
#include <config.h>
#include <ds3231.h>
#include <SPI.h>
#include <RA8875.h>

#define RA8875_INT 7
#define RA8875_CS 10
#define RA8875_RESET 9

RA8875 tft = RA8875(RA8875_CS, RA8875_RESET);

struct ts t;  // Pour DS3231
const char *strJdlS[]  = {"Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"};
const char *strMois[]  = {"Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre"};
int couleurRect, couleurRect1, x, etatAir, etatChauff, etatCO2;


// Affichage de l'heure et de la date

void affichDateHeure() {
  // Date
  tft.changeMode(TEXT); tft.setFontScale(1); tft.setTextColor(RA8875_WHITE, RA8875_BLACK);
  tft.setCursor(50, 0); tft.print(strJdlS[t.wday - 1]); tft.print(" ");
  tft.print(t.mday); tft.print(" ");
  tft.print(strMois[t.mon - 1]); tft.print(" "); tft.print(t.year);
  // Heure
  tft.setCursor(180, 28);
  if ((t.hour) < 10) {
    tft.print(" ");
  }
  tft.print(t.hour);
  tft.print(":");
  if ((t.min) < 10) {
    tft.print("0");
  }
  tft.print(t.min);
  tft.print(":");
  if ((t.sec) < 10) {
    tft.print("0");
  }
  tft.print(t.sec);
  tft.changeMode(GRAPHIC);
  tft.drawLine(0, 60, 480, 60, RA8875_CYAN);
}
void affichEclPPSec() {
  tft.changeMode(TEXT); tft.setFontScale(1); tft.setTextColor(RA8875_WHITE, RA8875_BLACK);
  tft.setCursor(0, 70); tft.print("Eclairage PP");
  x = 202; void rectVert();
  tft.setTextColor(RA8875_WHITE, RA8875_BLACK);
  tft.setCursor(280, 70); tft.print("Second."); tft.changeMode(GRAPHIC);
  tft.drawRect(410, 68, 50, 40, couleurRect1); tft.setCursor(419, 70); tft.print("NO");
}

void affichEclLed() {
  tft.changeMode(TEXT); tft.setFontScale(1); tft.setTextColor(RA8875_WHITE, RA8875_BLACK);
  tft.setCursor(0, 115); tft.print("Ecl LED"); tft.changeMode(GRAPHIC);
  tft.drawCircle(182, 132, 10, RA8875_WHITE); tft.fillCircle(182, 132, 8, RA8875_RED);
  tft.drawRect(202, 113, 50, 40, couleurRect); tft.setCursor(211, 115);
  tft.changeMode(TEXT); tft.print("OK"); tft.changeMode(GRAPHIC);
  tft.drawCircle(286, 132, 10, RA8875_WHITE); tft.fillCircle(286, 132, 8, RA8875_GREEN);
  tft.drawRect(306, 113, 50, 40, couleurRect); tft.setCursor(315, 115); 
  tft.changeMode(TEXT); tft.print("OK"); tft.changeMode(GRAPHIC);
  tft.drawCircle(390, 132, 10, RA8875_WHITE); tft.fillCircle(390, 132, 8, RA8875_BLUE);
  tft.drawRect(410, 113, 50, 40, couleurRect1); tft.setCursor(419, 115);
  tft.changeMode(TEXT); tft.print("NO");
}
void rectVert() {
  tft.changeMode(GRAPHIC);
  tft.drawRect(x, 68, 50, 40, couleurRect); tft.setCursor(x+9, 70); tft.print("OK");
  tft.changeMode(TEXT); 
}
void affichAirChauff() {
  tft.changeMode(TEXT); tft.setTextColor(RA8875_WHITE, RA8875_BLACK);
  tft.setCursor(0, 160); tft.print("Chauffage");
  tft.print(etatAir); tft.print("Air");
  tft.print(etatChauff);
}

//  Affichage des états CO2 et chauffage Jour/Nuit

void affichCO2Chauff() {

  tft.setCursor(0, 192); tft.print("Chauffage");
  tft.print(etatCO2); tft.print("CO2");
  tft.print(etatChauff);
}
void setup()
{
  Serial.begin(9600);
  Wire.begin();
  tft.begin(RA8875_480x272);
  tft.touchBegin(7);
  tft.touchEnable(true);
  tft.fillScreen(RA8875_BLACK);
  tft.PWMout(1, 150);
}


void loop()
{

  DS3231_get(&t);

  couleurRect = RA8875_GREEN;
  couleurRect1 = RA8875_RED;
  affichDateHeure();
  affichEclPPSec();
  affichEclLed();
  affichAirChauff();
  affichCO2Chauff();
}
  x = 202; void rectVert();

C'est une déclaration. Si tu veux appeler la fonction c'est

 x = 202; rectVert();

c'est ok ca fonctionne

Merci