FAQ ES33B08

Bonjour... Je m'appelle Eduardo et je teste la carte ES33B08.

J'essaie d'utiliser en même temps l'affichage à 7 segments et les sorties Darlington:

a) Le tube à 7 segments affiche l'adresse IP actuelle reçue par l'ESP32, après la connexion au WIFI

b) les sorties Darlington commanderont des LED de sortie et un moteur pas à pas

 

Est-ce possible?

 

Ci-dessous mon code actuel

 

#include 

 

// Broches connectées au 74HC595

const int CLOCK_595 = 27;

const int LATCH_595 = 14;

const int DATA_595  = 13;

const int OE_595    = 4;

 

// Broches pour clignoter

const int PULSE_PIN = 33;

const int DIR_PIN   = 25;

 

// Bouton pour une future extension

const int BUTTON_PIN = 18;

 

// Segments pour les chiffres 0–9 (anode commune)

uint8_t TUBE_SEG[] = {

  0x3f, 0x06, 0x5b, 0x4f,

  0x66, 0x6d, 0x7d, 0x07,

  0x7f, 0x6f

};

 

// Sélection du display à activer

uint8_t TUBE_NUM[8] = {

  0xfe, 0xfd, 0xfb, 0xf7,

  0xef, 0xdf, 0xbf, 0x7f

};

 

// Identifiants Wi-Fi

const char* ssid = "Posibras";

const char* password = "lucasmarzolla";

 

// IP à afficher

String ip_str = "";

int scrollIndex = 0;

unsigned long lastScroll = 0;

const int scrollDelay = 400;

 

uint8_t display_digits[4] = {0, 0, 0, 0};

bool digit_has_dot[4] = {false, false, false, false};

 

// Variables pour faire clignoter les broches

bool pinsOn = false;

unsigned long lastBlink = 0;

const int blinkInterval = 500; // 500 ms

 

void Send_Bytes(uint8_t dat)

{

  for (int i = 8; i >= 1; i--)

  {

    digitalWrite(DATA_595, (dat & 0x80) ? HIGH : LOW);

    dat <<= 1;

    digitalWrite(CLOCK_595, LOW);

    digitalWrite(CLOCK_595, HIGH);

  }

}

 

void Send_74HC595(uint8_t com_num)

{

  uint8_t seg_data = display_digits[com_num];

 

  if (digit_has_dot[com_num]) {

    seg_data &= 0x7F;

  } else {

    seg_data |= 0x80;

  }

 

  uint8_t bit_num = TUBE_NUM[com_num];

 

  Send_Bytes(0);

  Send_Bytes(bit_num);

  Send_Bytes(seg_data);

  digitalWrite(LATCH_595, LOW);

  digitalWrite(LATCH_595, HIGH);

}

 

void TubeDisplay4Digit()

{

  for (uint8_t com_num = 0; com_num < 4; com_num++)

  {

    Send_74HC595(com_num);

    delay(2);

  }

}

 

uint8_t getCharSegments(char c)

{

  if (c >= '0' && c <= '9') return TUBE_SEG[c - '0'];

  return 0x00;

}

 

void scrollIP()

{

  if (millis() - lastScroll >= scrollDelay)

  {

    lastScroll = millis();

 

    for (int i = 0; i < 4; i++)

    {

      digit_has_dot[i] = false;

      int pos = scrollIndex + i;

 

      if (pos >= ip_str.length()) {

        display_digits[i] = 0x00;

      } else {

        char c = ip_str.charAt(pos);

        if (c == '.') {

          if (i > 0) digit_has_dot[i - 1] = true;

         display_digits[i] = 0x00;

        } else {

         display_digits[i] = getCharSegments(c);

        }

      }

    }

 

    scrollIndex++;

    if (scrollIndex > ip_str.length() + 4) {

      scrollIndex = 0;

    }

  }

}

 

void setup()

{

  Serial.begin(115200);

 

  pinMode(CLOCK_595, OUTPUT);

  pinMode(LATCH_595, OUTPUT);

  pinMode(DATA_595, OUTPUT);

  pinMode(OE_595, OUTPUT);

  digitalWrite(OE_595, HIGH);

  Send_74HC595(0);

  digitalWrite(OE_595, LOW);

 

  // Broches pour clignoter

  pinMode(PULSE_PIN, OUTPUT);

  pinMode(DIR_PIN, OUTPUT);

 

  // Connexion au Wi-Fi

  Serial.println("Connexion au Wi-Fi...");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED)

  {

    delay(500);

    Serial.print(".");

  }

  Serial.println("\nConnecté !");

  Serial.print("Adresse IP : ");

  Serial.println(WiFi.localIP());

 

  IPAddress ip = WiFi.localIP();

  ip_str = String(ip[0]) + "." + String(ip[1]) + "." + String(ip[2]) + "." + String(ip[3]);

  Serial.print("IP pour l'affichage : ");

  Serial.println(ip_str);

}

 

void loop()

{

  scrollIP();

  TubeDisplay4Digit();

 

  // Faire clignoter les broches 33 et 25 toutes les 500 ms

  if (millis() - lastBlink >= blinkInterval)

  {

    lastBlink = millis();

    pinsOn = !pinsOn;

    digitalWrite(PULSE_PIN, pinsOn ? HIGH : LOW);

    digitalWrite(DIR_PIN, pinsOn ? HIGH : LOW);

  }

}

Réponse :

Nous ne savons pas si ce code est correct. Nous vous suggérons de tester chaque fonction une par une, puis d'ajouter progressivement les fonctions afin de déterminer où se trouve l'erreur.

Retour au blog

Laisser un commentaire