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

【雕爷学编程】Arduino动手做(104)---16X16点阵汉字屏模块2 中等

头像 驴友花雕 2023.07.29 175 1

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

 

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百零四:16X16点阵UART接口LED汉字显示屏模块

 

0.jpg
0-.jpg

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百零四: 16X16点阵串口LED汉字显示屏模块UART接口
1、安装库:marde
2、项目:显示“智”字
3、连线:
VDD  →  5V
GND → GND
TXD  →  D0
RXD  →  D1
 

 

代码
/*
【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验一百零八: 16X16点阵串口LED汉字显示屏模块UART接口
1、安装库:marde
2、项目:显示“智”字
3、连线:
VDD  →  5V
GND → GND
TXD  →  D0
RXD  →  D1
*/

#include <MdLep16X16.h>

byte message[][2]
={
  {0x20,0x00},//line_0
  {0x3e,0x7c},//line_1
  {0x48,0x44},//line_2
  {0x08,0x44},//line_3
  {0xff,0x44},//line_4
  {0x14,0x44},//line_5
  {0x22,0x7c},//line_6
  {0x40,0x00},//line_7
  {0x1f,0xf0},//line_8
  {0x10,0x10},//line_9
  {0x10,0x10},//line_10
  {0x1f,0xf0},//line_11
  {0x10,0x10},//line_12
  {0x10,0x10},//line_13
  {0x1f,0xf0},//line_14
  {0x10,0x10},//line_15
};

MdLep16X16 mdLep(0xFF, 0xFF, 0xFF, 0xFF);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(1000);
  mdLep.loadScreen((byte*)message);
}

void loop() {
  // put your main code here, to run repeatedly:   
}

Arduino实验场景图

 

13.jpg

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  项目之一:八段分频8X8点阵屏的音乐频谱灯

  实验开源代码

 

 

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(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;
  }
}

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
   项目之二:多档arduinoFFT浮点32段频谱仪
 

实验视频剪辑


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

 

实验视频剪辑2

 

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

 

 

 

Arduino实验场景图

 

17.gif

 

18.gif

实验场景图
用杜邦线引出D2管脚,作为触摸开关,可以转换五种显示频谱的模式,后面还有三种

 

19.jpg

项目之二:多档arduinoFFT浮点32段频谱仪

实验视频剪辑 3

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

 

实验场景动态图

 

20.gif

  项目之二:多档arduinoFFT浮点32段频谱仪

  实验视频剪辑 4

 

https://v.youku.com/v_show/id_XNTgyMTQ2NDIzMg==.html?spm=a2hcb.playlsit.page.7

 


实验场景动态图4

 

21.gif

   项目之二:多档arduinoFFT浮点32段频谱仪

  实验视频剪辑 5

 

 https://v.youku.com/v_show/id_XNTgyMTc5OTQ0MA==.html?spm=a2hcb.playlsit.page.5

 

 

实验场景动态图 5

 

22.gif

 

  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  项目之三:红绿色32段级联频谱点阵屏灯(FFT算法)

  实验开源代码
 

 

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(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);

  }

}

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
 项目之三:红绿色32段级联频谱点阵屏灯(FFT算法)

 

实验视频剪辑 1
https://v.youku.com/v_show/id_XNTgyMjA0Mjg0NA==.html?spm=a2hcb.playlsit.page.3

 

实验场景动态图
 

 

23.gif

评论

user-avatar
  • hacker_

    hacker_2023.07.31

    666

    0
    icon 他的勋章
      展开更多