[Diao Ye learns programming] Arduino hands-on (99) --- 8X32 LED dot matrix screen module 4

The reference to 37 sensors and actuators has been widely circulated on the Internet. In fact, there must be more than 37 sensor modules compatible with Arduino. In view of the fact that I have accumulated some sensor and actuator modules on hand, according to the concept of practicing true knowledge (must be done), for the purpose of learning and communication, I am going to try a series of experiments one by one, regardless of success (the program goes through) or not, They will be recorded - small progress or unsolvable problems, hoping to inspire others.

[Arduino] 168 kinds of sensor module series experiments (data code + simulation programming + graphics programming)
Experiment 99: 8X32 LED dot matrix display module MAX7219 output common cathode 5V four-bit dot matrix module

insert image description here

Knowledge points: MAX7219
is a multi-digit LED display driver launched by MAXIM Company in the United States. It uses a 3-wire serial interface to transmit data and can be directly connected to the single-chip interface. Users can easily modify its internal parameters to realize multi-digit LED display. It contains hardware dynamic scanning circuit, BCD decoder, segment driver and bit driver. In addition, it also contains 8X8-bit static RAM inside, which is used to store the display data of 8 figures. Obviously, it can directly drive a 64-segment LED dot matrix display. When multiple MAX7219s are cascaded, more LED dot-matrix displays can be controlled. The displayed data is sent to MAX7219 for display after being processed by the single-chip microcomputer.

The MAX7219/MAX7221 are integrated serial input/output common-cathode display drivers that connect a microprocessor to an 8-digit 7-segment LED display, as well as a bar graph display or 64 individual LEDs. It includes an on-chip B-type BCD encoder, multi-channel scanning circuit, segment driver, and an 8*8 static RAM to store each data. Only one external register is used to set the segment current for each LED. The MAX7221 is compatible with SPI™, QSPI™, and MICROWIRE™, and it has a segment drive that limits the slew current to reduce EMI (electromagnetic interference). A convenient four-wire serial interface can interface with all common microprocessors. Each data address can be updated without rewriting all displays. The MAX7219/MAX7221 also allow the user to choose to encode or not encode each data. The entire device includes a 150µA low-power shutdown mode, analog and digital brightness controls, a scan limit register allowing the user to display 1-8 bits of data, and a detection mode that makes all LEDs illuminate.

insert image description here
8X32 LED dot matrix display module MAX7219 output common cathode 5V four bit dot matrix module

8X32 LED dot matrix display cascade module, MAX7219 is an integrated serial input/output common-cathode display driver, which connects the microprocessor and 8-digit 7-segment digital LED display, and can also be connected to a bar graph display or 64 individual LEDs. It includes an on-chip B-type BCD encoder, multi-channel scanning circuit, segment driver, and an 8*8 static RAM to store each data. Only one external register is used to set the segment current for each LED. A convenient four-wire serial interface can interface with all common microprocessors. Each data address can be updated without rewriting all displays. The MAX7219 also allows the user to choose to encode or not encode each data. The entire device includes a 150µA low-power shutdown mode, analog and digital brightness controls, a scan limit register allowing the user to display 1-8 bits of data, and a detection mode that makes all LEDs illuminate. Only 3 IO ports are needed to drive 1 dot matrix! No flickering when the dot matrix display! Cascading is supported!

insert image description here
8X32 LED dot matrix display module reference circuit schematic diagram

insert image description here
insert image description here
Wiring diagram of Arduino experiment

insert image description here
【HuaDiao hands-on】Interesting and fun music visualization series of small projects (08) - four-digit 32-segment dot matrix screen
Project 2: Multi-file arduinoFFT floating-point 32-segment spectrum analyzer

Experimental open source code

/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(08)---四位32段点阵屏
  项目之二:多档arduinoFFT浮点32段频谱仪
  接脚连线:MAX9814 接A0
  MAX7219 UNO
  VCC →→→→→ 5V
  GND →→→→→ GND
  DIN →→→→→ D11(数据,数据接收引脚)
  CS →→→→→ D10(负载,命令接收引脚)
  CLK →→→→→ D13(时钟,时钟引脚)
*/

#include <arduinoFFT.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define SAMPLES 64
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES  4
#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10
#define  xres 32
#define  yres 8


int MY_ARRAY[] = {
    
    0, 128, 192, 224, 240, 248, 252, 254, 255};
int MY_MODE_1[] = {
    
    0, 128, 192, 224, 240, 248, 252, 254, 255};
int MY_MODE_2[] = {
    
    0, 128, 64, 32, 16, 8, 4, 2, 1};
int MY_MODE_3[] = {
    
    0, 128, 192, 160, 144, 136, 132, 130, 129};
int MY_MODE_4[] = {
    
    0, 128, 192, 160, 208, 232, 244, 250, 253};
int MY_MODE_5[] = {
    
    0, 1, 3, 7, 15, 31, 63, 127, 255};


double vReal[SAMPLES];
double vImag[SAMPLES];
char data_avgs[xres];

int yvalue;
int displaycolumn , displayvalue;
int peaks[xres];
const int buttonPin = 2;
int state = HIGH;
int previousState = LOW;
int displaymode = 1;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;


MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
arduinoFFT FFT = arduinoFFT();



void setup() {
    
    

  ADCSRA = 0b11100101;
  ADMUX = 0b00000000;
  pinMode(buttonPin, INPUT);
  mx.begin();
  delay(50);
}

void loop() {
    
    
  // ++ Sampling
  for (int i = 0; i < SAMPLES; i++)
  {
    
    
    while (!(ADCSRA & 0x10));
    ADCSRA = 0b11110101 ;
    int value = ADC - 512 ;
    vReal[i] = value / 8;
    vImag[i] = 0;
  }

  FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
  FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
  FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);

  int step = (SAMPLES / 2) / xres;
  int c = 0;
  for (int i = 0; i < (SAMPLES / 2); i += step)
  {
    
    
    data_avgs[c] = 0;
    for (int k = 0 ; k < step ; k++) {
    
    
      data_avgs[c] = data_avgs[c] + vReal[i + k];
    }
    data_avgs[c] = data_avgs[c] / step;
    c++;
  }

  for (int i = 0; i < xres; i++)
  {
    
    
    data_avgs[i] = constrain(data_avgs[i], 0, 80);
    data_avgs[i] = map(data_avgs[i], 0, 80, 0, yres);
    yvalue = data_avgs[i];

    peaks[i] = peaks[i] - 1;
    if (yvalue > peaks[i])
      peaks[i] = yvalue ;
    yvalue = peaks[i];
    displayvalue = MY_ARRAY[yvalue];
    displaycolumn = 15 - i;
    mx.setColumn(displaycolumn, displayvalue);
  }

  displayModeChange ();
}

void displayModeChange() {
    
    
  int reading = digitalRead(buttonPin);
  if (reading == HIGH && previousState == LOW && millis() - lastDebounceTime > debounceDelay)

  {
    
    

    switch (displaymode) {
    
    
      case 1:
        displaymode = 2;
        for (int i = 0 ; i <= 8 ; i++ ) {
    
    
          MY_ARRAY[i] = MY_MODE_2[i];
        }
        break;
      case 2:
        displaymode = 3;
        for (int i = 0 ; i <= 8 ; i++ ) {
    
    
          MY_ARRAY[i] = MY_MODE_3[i];
        }
        break;
      case 3:
        displaymode = 4;
        for (int i = 0 ; i <= 8 ; i++ ) {
    
    
          MY_ARRAY[i] = MY_MODE_4[i];
        }
        break;
      case 4:
        displaymode = 5;
        for (int i = 0 ; i <= 8 ; i++ ) {
    
    
          MY_ARRAY[i] = MY_MODE_5[i];
        }
        break;
      case 5:
        displaymode = 1;
        for (int i = 0 ; i <= 8 ; i++ ) {
    
    
          MY_ARRAY[i] = MY_MODE_1[i];
        }
        break;
    }

    lastDebounceTime = millis();
  }
  previousState = reading;
}

【HuaDiao hands-on】Interesting and fun music visualization series of small projects (08) - four-digit 32-segment dot matrix screen
Project 2: Multi-file arduinoFFT floating-point 32-segment spectrum analyzer

Experimental video clip 1
https://v.youku.com/v_show/id_XNTgyMTY3NTQwNA==.html?spm=a2hcb.playlsit.page.1

Experimental scene dynamic diagram

insert image description here

【HuaDiao hands-on】Interesting and fun music visualization series of small projects (08) - four-digit 32-segment dot matrix screen
Project 2: Multi-file arduinoFFT floating-point 32-segment spectrum analyzer

Experimental video clip 7
https://v.youku.com/v_show/id_XNTgyMjA0MTI1Mg==.html?spm=a2hcb.playlsit.page.1

Experimental scene dynamic figure 7
insert image description here

【HuaDiao hands-on】Interesting and fun music visualization series of small projects (08) - four-digit 32-segment dot matrix screen
Project 2: Multi-file arduinoFFT floating-point 32-segment spectrum analyzer

Experimental video clip 8
https://v.youku.com/v_show/id_XNTgyMjA0MTM2MA==.html?spm=a2hcb.playlsit.page.1

Experimental Scene Dynamic Diagram 8
insert image description here

【HuaDiao hands-on】Interesting and fun music visualization series of small projects (08) - four-digit 32-segment dot-matrix screen
Project 3: Red and green 32-segment cascaded spectrum dot-matrix screen lights (FFT algorithm)

Experimental open source code

/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(08)---四位32段点阵屏
  项目之三:红绿色32段级联频谱点阵屏灯(FFT算法)
  接脚连线:MAX9814 接A0
  MAX7219 UNO
  VCC →→→→→ 5V
  GND →→→→→ GND
  DIN →→→→→ D11(数据,数据接收引脚)
  CS →→→→→ D10(负载,命令接收引脚)
  CLK →→→→→ D13(时钟,时钟引脚)
*/

#include <arduinoFFT.h>

#include <MD_MAX72xx.h>

#include <SPI.h>

MD_MAX72XX disp = MD_MAX72XX(MD_MAX72XX::FC16_HW, 10, 1);

arduinoFFT FFT = arduinoFFT();

double realComponent[64];

double imagComponent[64];

int spectralHeight[] = {
    
    0b00000000, 0b10000000, 0b11000000,

                        0b11100000, 0b11110000, 0b11111000,

                        0b11111100, 0b11111110, 0b11111111
                       };

int index, c, value;

void setup()

{
    
    

  disp.begin();

  Serial.begin(9600);

}

void loop()

{
    
    

  int sensitivity = map(analogRead(A0), 0, 1023, 50, 100);

  Serial.println (analogRead(A0));

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

  {
    
    

    realComponent[i] = analogRead(A7) / sensitivity;

    imagComponent[i] = 0;

  }

  FFT.Windowing(realComponent, 64, FFT_WIN_TYP_HAMMING, FFT_FORWARD);

  FFT.Compute(realComponent, imagComponent, 64, FFT_FORWARD);

  FFT.ComplexToMagnitude(realComponent, imagComponent, 64);

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

  {
    
    

    realComponent[i] = constrain(realComponent[i], 0, 80);

    realComponent[i] = map(realComponent[i], 0, 80, 0, 8);

    index = realComponent[i];

    value = spectralHeight[index];

    c = 31 - i;

    disp.setColumn(c, value);

  }

}

【HuaDiao hands-on】Interesting and fun music visualization series of small projects (08) - four-digit 32-segment dot-matrix screen
Project 3: Red and green 32-segment cascaded spectrum dot-matrix screen lights (FFT algorithm)

Experiment Video Clip 2

https://v.youku.com/v_show/id_XNTgyMTc1NTk2OA==.html?spm=a2hcb.playlsit.page.1

Experimental scene dynamic diagram 2

insert image description here

【HuaDiao hands-on】Interesting and fun music visualization series of small projects
Project 4: Dynamic Spectrum Analyzer with FFT Algorithm Dual Dot Matrix Screen

Experimental video clip

https://v.youku.com/v_show/id_XNTgyMjEwNjcwMA==.html?spm=a2hcb.playlsit.page.1

Experimental scene graph

insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/131990543