🔲 Aplicação 12 – Display de Matriz de LEDs 8×64 com Arduino e MAX7219

🎯 Objetivo

Controlar um display de matriz de LEDs 8×64 usando o driver MAX7219, para exibir mensagens rolantes, como no nosso exemplo com a palavra "ELETROCONDUTOR".
Esse projeto é ideal para aprender sobre multiplexação, controle serial de LEDs e criação de efeitos visuais dinâmicos.


🛠 Componentes Necessários

  • 1 × Arduino UNO (ou compatível)

  • 1 × Módulo de matriz de LEDs 8×64 (com MAX7219)

  • Jumpers macho-macho

  • Fonte de alimentação (se necessário para brilho máximo)


⚡ O que é o MAX7219?



O MAX7219 é um driver de LEDs com controle serial capaz de gerenciar até 64 LEDs individualmente, com brilho ajustável via software.
Principais vantagens:

  • Apenas 3 pinos de controle (DIN, CLK, CS) para comunicação com o Arduino.

  • Controle individual de cada LED sem necessidade de hardware extra.

  • Multiplexação automática, reduzindo a carga de processamento do microcontrolador.


📊 Como Funciona no Projeto

  1. O Arduino envia os dados (padrões de LEDs acesos) pelo protocolo serial simples do MAX7219.

  2. O MAX7219 realiza a varredura das linhas e colunas, acendendo LEDs muito rapidamente para formar letras e símbolos.

  3. A biblioteca MD_Parola é utilizada para animar o texto “ELETROCONDUTOR” rolando suavemente no display.


📷 Montagem do Circuito

Conexões principais (Arduino → MAX7219):

  • DIN → Pino 11

  • CLK → Pino 13

  • CS → Pino 10

  • VCC → 5V

  • GND → GND

(Inserir imagem real do seu circuito montado)


📌 Dicas Técnicas

  • Ajuste o brilho com setIntensity(nível) para equilibrar consumo e visibilidade.

  • Mensagens longas podem ser roladas automaticamente com displayScroll.

  • É possível armazenar várias mensagens e alternar entre elas sem regravar o código.





#include <LedControl.h>

// pinos do Arduino para o módulo MAX7219
#define DIN_PIN    11
#define CLK_PIN    13
#define CS_PIN     10
#define NUM_DEVICES 8   // Dobrado: 8 módulos de 8x8 -> 64x8

LedControl lc = LedControl(DIN_PIN, CLK_PIN, CS_PIN, NUM_DEVICES);

// framebuffer: 64 colunas (cada byte = 8 linhas)
byte cols[NUM_DEVICES * 8];

// Fonte 5x7 — ASCII 32..90 (espaço, sinais, 0-9, A-Z)
const byte font[][5] = {
  {0x00,0x00,0x00,0x00,0x00}, // 32  space
  {0x00,0x00,0x5F,0x00,0x00}, // 33  !
  {0x00,0x07,0x00,0x07,0x00}, // 34  "
  {0x14,0x7F,0x14,0x7F,0x14}, // 35  #
  {0x24,0x2A,0x7F,0x2A,0x12}, // 36  $
  {0x23,0x13,0x08,0x64,0x62}, // 37  %
  {0x36,0x49,0x55,0x22,0x50}, // 38  &
  {0x00,0x05,0x03,0x00,0x00}, // 39  '
  {0x00,0x1C,0x22,0x41,0x00}, // 40  (
  {0x00,0x41,0x22,0x1C,0x00}, // 41  )
  {0x14,0x08,0x3E,0x08,0x14}, // 42  *
  {0x08,0x08,0x3E,0x08,0x08}, // 43  +
  {0x00,0x50,0x30,0x00,0x00}, // 44  ,
  {0x08,0x08,0x08,0x08,0x08}, // 45  -
  {0x00,0x60,0x60,0x00,0x00}, // 46  .
  {0x20,0x10,0x08,0x04,0x02}, // 47  /
  {0x3E,0x51,0x49,0x45,0x3E}, // 48  0
  {0x00,0x42,0x7F,0x40,0x00}, // 49  1
  {0x42,0x61,0x51,0x49,0x46}, // 50  2
  {0x21,0x41,0x45,0x4B,0x31}, // 51  3
  {0x18,0x14,0x12,0x7F,0x10}, // 52  4
  {0x27,0x45,0x45,0x45,0x39}, // 53  5
  {0x3C,0x4A,0x49,0x49,0x30}, // 54  6
  {0x01,0x71,0x09,0x05,0x03}, // 55  7
  {0x36,0x49,0x49,0x49,0x36}, // 56  8
  {0x06,0x49,0x49,0x29,0x1E}, // 57  9
  {0x00,0x36,0x36,0x00,0x00}, // 58  :
  {0x00,0x56,0x36,0x00,0x00}, // 59  ;
  {0x08,0x14,0x22,0x41,0x00}, // 60  <
  {0x14,0x14,0x14,0x14,0x14}, // 61  =
  {0x00,0x41,0x22,0x14,0x08}, // 62  >
  {0x02,0x01,0x51,0x09,0x06}, // 63  ?
  {0x32,0x49,0x79,0x41,0x3E}, // 64  @
  {0x7E,0x11,0x11,0x11,0x7E}, // 65  A
  {0x7F,0x49,0x49,0x49,0x36}, // 66  B
  {0x3E,0x41,0x41,0x41,0x22}, // 67  C
  {0x7F,0x41,0x41,0x22,0x1C}, // 68  D
  {0x7F,0x49,0x49,0x49,0x41}, // 69  E
  {0x7F,0x09,0x09,0x09,0x01}, // 70  F
  {0x3E,0x41,0x49,0x49,0x7A}, // 71  G
  {0x7F,0x08,0x08,0x08,0x7F}, // 72  H
  {0x00,0x41,0x7F,0x41,0x00}, // 73  I
  {0x20,0x40,0x41,0x3F,0x01}, // 74  J
  {0x7F,0x08,0x14,0x22,0x41}, // 75  K
  {0x7F,0x40,0x40,0x40,0x40}, // 76  L
  {0x7F,0x02,0x04,0x02,0x7F}, // 77  M
  {0x7F,0x04,0x08,0x10,0x7F}, // 78  N
  {0x3E,0x41,0x41,0x41,0x3E}, // 79  O
  {0x7F,0x09,0x09,0x09,0x06}, // 80  P
  {0x3E,0x41,0x51,0x21,0x5E}, // 81  Q
  {0x7F,0x09,0x19,0x29,0x46}, // 82  R
  {0x46,0x49,0x49,0x49,0x31}, // 83  S
  {0x01,0x01,0x7F,0x01,0x01}, // 84  T
  {0x3F,0x40,0x40,0x40,0x3F}, // 85  U
  {0x1F,0x20,0x40,0x20,0x1F}, // 86  V
  {0x3F,0x40,0x38,0x40,0x3F}, // 87  W
  {0x63,0x14,0x08,0x14,0x63}, // 88  X
  {0x07,0x08,0x70,0x08,0x07}, // 89  Y
  {0x61,0x51,0x49,0x45,0x43}  // 90  Z
};

const char message[] = " ELETROCONDUTOR ";

// Função para inverter bits da coluna
byte reverseBits(byte b) {
  b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
  b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
  b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
  return b;
}

// Atualiza display a partir do buffer, corrigindo a ordem dos módulos
void updateDisplayFromBuffer() {
  for (int col = 0; col < NUM_DEVICES * 8; col++) {
    int dev = col / 8;
    int colInDev = col % 8;
    int devIndex = (NUM_DEVICES - 1) - dev; // inversão da ordem dos módulos
    int flippedCol = 7 - colInDev;          // inverte ordem das colunas no módulo
    lc.setColumn(devIndex, flippedCol, reverseBits(cols[col]));
  }
}

void clearBuffer() {
  for (int i = 0; i < NUM_DEVICES * 8; i++) cols[i] = 0x00;
  updateDisplayFromBuffer();
}

void shiftLeftBuffer() {
  for (int i = 0; i < NUM_DEVICES * 8 - 1; i++) cols[i] = cols[i + 1];
  cols[NUM_DEVICES * 8 - 1] = 0x00;
}

const byte* getCharBitmap(char ch) {
  if (ch >= 97 && ch <= 122) ch -= 32;
  if (ch < 32 || ch > 90) ch = 32;
  return font[ch - 32];
}

void pushColumnToBuffer(byte column) {
  shiftLeftBuffer();
  cols[NUM_DEVICES * 8 - 1] = column;
  updateDisplayFromBuffer();
}

void setup() {
  for (int dev = 0; dev < NUM_DEVICES; dev++) {
    lc.shutdown(dev, false);
    lc.setIntensity(dev, 8);
    lc.clearDisplay(dev);
  }
  for (int i = 0; i < NUM_DEVICES * 8; i++) cols[i] = 0xFF;
  updateDisplayFromBuffer();
  delay(1500);
  clearBuffer();
}

void loop() {
  const int speedMs = 80;
  while (true) {
    const char* p = message;
    while (*p) {
      const byte* bmp = getCharBitmap(*p);
      for (int c = 0; c < 5; c++) {
        pushColumnToBuffer(bmp[c]);
        delay(speedMs);
      }
      pushColumnToBuffer(0x00);
      delay(speedMs);
      p++;
    }
    delay(400);
  }
}

Comentários

Postagens mais visitadas deste blog

contador 9999 com pic 16f628

CNC fotos cordenadas x y z dicas

codigo assembler braço mecanico para 5 motores