回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

【雕爷学编程】Arduino动手做(99)---8X32 LED点阵屏模块3 中等

头像 驴友花雕 2023.07.29 71 3

37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手尝试系列实验,不管成功(程序走通)与否,都会记录下来—小小的进步或是搞不掂的问题,希望能够抛砖引玉。

 

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验九十九:8X32 LED点阵屏显示模块 MAX7219 输出 共阴 5V 四位点阵模组
 

0-.jpg

实验开源图形编程(Mind+、编玩边学)

 

25.jpg

gif5新文件.gif

实验开源仿真编程(Linkboy V5.33)

 

26.gif

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

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

#include "LedControl.h"

/* Led matrix - Max7219 Declared */
LedControl lc = LedControl(11, 13, 10, 1);

const int maxScale = 11;

/* Sensor - Max9812 Declared */
const int sensorPin = A0;
const int sampleWindow = 50; // 50ms = 20Hz
unsigned int sample;

unsigned long startMillis;
unsigned long timeCycle;

unsigned int signalMax = 0;
unsigned int signalMin = 1024;
unsigned char index = 0;

unsigned int peakToPeak[8];
unsigned int displayPeak[8];
unsigned int temp[8] = {0, 0, 0, 0, 0, 0, 0, 0};
unsigned int signalMaxBuff[8];
unsigned int signalMinBuff[8];


void setup() {
  // Led matrix
  lc.shutdown(0, false); // bật hiện thị
  lc.setIntensity(0, 2); // chỉnh độ sáng
  lc.clearDisplay(0); // tắt tất cả led

  Serial.begin(9600);
}

void loop() {
  startMillis = millis();
  //peakToPeak = 0;

  signalMax = 0;
  signalMin = 1024;

  // Get data in 50ms
  while (millis() - startMillis < sampleWindow) {
    sample = analogRead(sensorPin);

    if (sample < 1024) {
      if (sample > signalMax) {
        signalMax = sample;
      }
      if (sample < signalMin) {
        signalMin = sample;
      }
    }

    // 20Hz - 64Hz - 125Hz - 250Hz - 500Hz - 1kHz (timeCycle = 1/F)(ms)
    timeCycle = millis() - startMillis;
    if (timeCycle == 1 || timeCycle == 2 || timeCycle == 4 || timeCycle == 8
        || timeCycle == 16 || timeCycle == 32 || timeCycle == 40 || timeCycle == 50) {
      signalMaxBuff[index] = signalMax;
      signalMinBuff[index] = signalMin;
      index = (index + 1) % 8;
      delay(1);
      Serial.println(timeCycle);
    }
  }

  // Delete pointer to array
  index = 0;

  // Calculation after get samples
  for (int i = 0; i < 8; i++) { // i = row (led matrix)
    // sound level
    peakToPeak[i] = signalMaxBuff[i] - signalMinBuff[i];

    // Map 1v p-p level to the max scale of the display
    displayPeak[i] = map(peakToPeak[i], 0, 1023, 0, maxScale);

    // Show to led matrix
    displayLed(displayPeak[i], i);

    // Led drop down
    if (displayPeak[i] >= temp[i]) {
      temp[i] = displayPeak[i];
    }
    else {
      temp[i]--;
    }

    lc.setLed(0, i, temp[i], true);
    delayMicroseconds(10);
  }

}

void displayLed(int displayPeak, int row) {
  switch (displayPeak) {
    case 0 : lc.setRow(0, row, 0x80); break;
    case 1 : lc.setRow(0, row, 0xC0); break;
    case 2 : lc.setRow(0, row, 0xE0); break;
    case 3 : lc.setRow(0, row, 0xF0); break;
    case 4 : lc.setRow(0, row, 0xF8); break;
    case 5 : lc.setRow(0, row, 0xFC); break;
    case 6 : lc.setRow(0, row, 0xFE); break;
    case 7 : lc.setRow(0, row, 0xFF); break;
  }
}

实验场景动态图

 

实验视频剪辑


 

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

 

 

image.png

评论

user-avatar
  • 一地鸡毛

    一地鸡毛2024.01.12

    厉害厉害

    1
    • 驴友花雕

      驴友花雕2024.01.26

      谢谢老师的鼓励

  • hacker_

    hacker_2023.08.02

    666

    0
    icon 他的勋章
      展开更多