驴友花雕
发表于 2021-7-5 06:46:01
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十一:使用Matrix库的三色LED
实验开源代码
/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十一:使用Matrix库的三色LED
接脚连线:
MAX7219 UNO
VCC→→→→→ 5V
GND→→→→→ GND
DIN→→→→→ D12(数据,数据接收引脚)
CS →→→→→ D11(负载,命令接收引脚)
CLK→→→→→ D10(时钟,时钟引脚)
*/
#include <Sprite.h>// Sprite before Matrix
#include <Matrix.h>
//DIN, CLK, CS, #chips
Matrix myLeds = Matrix(12, 10, 11, 3);
Sprite letter_D = Sprite(6, 8,
B111100,
B111110,
B110111,
B110011,
B110011,
B110111,
B111110,
B111100
);
Sprite letter_E = Sprite(5, 8,
B11111,
B11111,
B11000,
B11110,
B11110,
B11000,
B11111,
B11111
);
Sprite letter_L = Sprite(5, 8,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11111,
B11111
);
void setup() {
myLeds.setBrightness(0);
}
void loop() {
myLeds.clear();
delay(1000);
myLeds.write(17, 0, letter_L);
delay(1000);
myLeds.write(9, 0, letter_E);
delay(1000);
myLeds.write(1, 0, letter_D);
delay(1000);
}
驴友花雕
发表于 2021-7-5 06:58:16
本帖最后由 驴友花雕 于 2021-8-21 13:33 编辑
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度项目三十一:使用Matrix库的三色LED
实验场景图片
驴友花雕
发表于 2021-7-5 07:00:48
Matrix库的几个函数
基本用法,仅限像素
Matrix myLeds = Matrix(DIN,CLK,LOAD,numChips);
使用您选择的名称创建Matrix对象的实例。DIN,CLK和LOAD是连接这些信号的引脚号。如果连接了多个单独连接的MAX7219芯片,则可以创建多个对象。
myLeds.clear();
清除整个显示屏。
myLeds.setBrightness(15);
设置显示亮度,从0到15(最亮)。
myLeds.write(x,y,value);
更改单个像素。对于关闭,值应为LOW,对于on,值应为HIGH。
基本用法,使用Sprite
Sprite myIcon = Sprite(宽度,高度,B11000,B11000,B11111,B11111);
创建一个精灵对象。您可以根据需要创建任意数量的精灵,每个精灵都有一个唯一的名称。宽度应与每个数据值中的位数匹配,高度应与数据值的数量匹配。
myLeds.write(x,y,myIcon);
在显示屏上绘制一个闪烁的精灵。
Sprite库允许创建与Matrix库一起使用的图像精灵
Sprite
启动LCD库。
width()
返回精灵的宽度(以像素为单位)。
height()
返回精灵的高度(以像素为单位)。
write()
将数据写入精灵的x,y位置。
read()
返回存储在sprite的x,y位置的数据。
驴友花雕
发表于 2021-7-5 07:17:15
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十二:建立字母库,横式滚动文本显示(三级联)
实验开源代码
/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十二:建立字母库,横式滚动文本显示(三级联)
接线接脚:
MAX7219 UNO
VCC→→→→→ 5V
GND→→→→→ GND
DIN→→→→→ D12(数据,数据接收引脚)
CS →→→→→ D11(负载,命令接收引脚)
CLK→→→→→ D10(时钟,时钟引脚)
*/
#include <MaxMatrix.h>
#include <avr/pgmspace.h>
PROGMEM const unsigned char CH[] = {
3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
};
int DIN = 12;
int CLK = 10;
int CS = 11;
int maxInUse = 3;
MaxMatrix m(DIN, CS, CLK, maxInUse);
byte buffer;
char text[]= "Hello Eagler8 "; // 滚动文本
void setup() {
m.init(); // 模块初始化
m.setIntensity(8); // 点阵亮度 0-15
}
void loop() {
printStringWithShift(text, 100); // (文字,滚动速度)
}
// 显示=滚动提取的字符
void printCharWithShift(char c, int shift_speed) {
if (c < 32) return;
c -= 32;
memcpy_P(buffer, CH + 7 * c, 7);
m.writeSprite(32, 0, buffer);
m.setColumn(32 + buffer, 0);
for (int i = 0; i < buffer + 1; i++){
delay(shift_speed);
m.shiftLeft(false, false);
}
}
// 从文本字符串中提取字符
void printStringWithShift(char* s, int shift_speed) {
while (*s != 0) {
printCharWithShift(*s, shift_speed);
s++;
}
}
驴友花雕
发表于 2021-7-5 07:31:18
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十二:建立字母库,横式滚动文本显示(三级联)
实验场景图片
驴友花雕
发表于 2021-7-8 11:15:03
:P大小点阵屏的对比
威威子爱捣鼓
发表于 2021-7-25 11:12:42
太全了,一时有点晕
驴友花雕
发表于 2021-8-3 21:11:26
威威子爱捣鼓 发表于 2021-7-25 11:12
太全了,一时有点晕
谢谢鼓励,这个模块比较少见
虾虾^0^
发表于 2021-8-12 15:50:47
厉害厉害厉害厉害厉害
驴友花雕
发表于 2021-8-12 16:45:32
虾虾^0^ 发表于 2021-8-12 15:50
厉害厉害厉害厉害厉害
谢谢虾虾的鼓励
驴友花雕
发表于 2021-9-8 07:57:53
Arduino 系列传感器和执行器模块实验目录清单:
一块扩展板完成Arduino的10类37项实验(代码+图形+仿真)
https://mc.dfrobot.com.cn/thread-280845-1-1.html
连杆形式的腿机构十一种:盘点机器人行走背后的机械原理
https://mc.dfrobot.com.cn/thread-308097-1-1.html
【花雕动手做】超低成本,尝试五十元的麦克纳姆轮小车!
https://mc.dfrobot.com.cn/thread-307863-1-1.html
【花雕动手做】超迷你哦,用徽商香烟盒做个智能小车!
https://mc.dfrobot.com.cn/thread-307907-1-1.html
【花雕动手做】太搞笑啦,一支胶管制成二只蠕动机器人
https://mc.dfrobot.com.cn/thread-308046-1-1.html
【花雕动手做】快餐盒盖,极低成本搭建机器人实验平台
https://mc.dfrobot.com.cn/thread-308063-1-1.html
【花雕动手做】特别苗条,使用微波传感器控制的纤细小车
https://mc.dfrobot.com.cn/thread-308866-1-1.html
【花雕动手做】脑洞大开、五花八门的简易机器人66种
https://mc.dfrobot.com.cn/thread-307900-1-1.html
实验一百五十八:QMC5883L电子指南针罗盘模块 三轴磁场传感器GY-271
https://mc.dfrobot.com.cn/thread-308195-1-1.html
实验一百六十三:BMI160 6轴惯性运动传感器 16位3轴加速度+超低功耗3轴陀螺仪I2C/SPI 14LGA
https://mc.dfrobot.com.cn/thread-310371-1-1.html
实验一百六十五:2.4 英寸 TFT LCD 触摸屏模块 XPT2046 PCB ILI9341 240x320 像素 8 位 SPI 串口显示器
https://mc.dfrobot.com.cn/thread-309803-1-1.html
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
https://mc.dfrobot.com.cn/thread-309845-1-1.html
实验一百八十三:GY-530 VL53L0X 激光测距 ToF测距 飞行时间测距传感器模块 IIC通信协议
https://mc.dfrobot.com.cn/thread-310273-1-1.html
实验一百八十五:MAX4466声音传感器 驻极体话筒放大器 麦克风可调功放模块 microphone
https://mc.dfrobot.com.cn/thread-310193-1-1.html
实验一百八十九:TDA1308 硅麦克风 数字咪头放大模块 拾音器放大板 楼氏SUNLEPHANT
https://mc.dfrobot.com.cn/thread-310246-1-1.html
实验一百九十三:TCS34725颜色识别传感器 RGB IIC明光感应模块 ColorSensor
https://mc.dfrobot.com.cn/thread-310209-1-1.html
实验二百:RCWL-0515微波雷达感应开关 人体感应 智能感应探测传感器 12-15米远距离2.7G微波检测模块
https://mc.dfrobot.com.cn/thread-310313-1-1.html
实验二百零三:Air724UG合宙 Cat14G模块 DTU物联网UART串口通信数据TCP透传 核心板组合套餐
https://mc.dfrobot.com.cn/thread-310342-1-1.html
实验二百零九:Gravity: I2C & UART BC20 NB-IoT & GNSS通信模块 NB-IoT广域低功耗无线通信 GPS/北斗精准定位
https://mc.dfrobot.com.cn/thread-310433-1-1.html
驴友花雕
发表于 2021-10-1 14:43:16
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十三:动态音乐频谱仪
实验开源代码
/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十三:动态音乐频谱仪
接脚连线:
MAX7219 UNO
VCC→→→→→ 5V
GND→→→→→ GND
DIN→→→→→ D12(数据,数据接收引脚)
CS →→→→→ D11(负载,命令接收引脚)
CLK→→→→→ D10(时钟,时钟引脚)
*/
#include "LedControl.h"
/* Led matrix - Max7219 Declared */
LedControl lc = LedControl(12, 11, 10, 1);
const int maxScale = 11;
/*Sensor - Max9812 Declared */
const int sensorPin = A4;
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;
unsigned int displayPeak;
unsigned int temp = {0, 0, 0, 0, 0, 0, 0, 0};
unsigned int signalMaxBuff;
unsigned int signalMinBuff;
void setup() {
// Led matrix
lc.shutdown(0, false); // bật hiện thị
lc.setIntensity(0, 1); // 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 = signalMax;
signalMinBuff = 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 = signalMaxBuff - signalMinBuff;
// Map 1v p-p level to the max scale of the display
displayPeak = map(peakToPeak, 0, 1023, 0, maxScale);
// Show to led matrix
displayLed(displayPeak, i);
// Led drop down
if (displayPeak >= temp) {
temp = displayPeak;
}
else {
temp--;
}
lc.setLed(0, i, temp, true);
delayMicroseconds(250);
}
}
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;
}
}
驴友花雕
发表于 2021-10-1 14:46:53
实验场景图
驴友花雕
发表于 2021-10-1 15:55:28
【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十三:动态音乐频谱仪
实验视频剪辑
https://v.youku.com/v_show/id_XNTgxMDQ2OTc2MA==.html?spm=a2hcb.playlsit.page.1
https://v.youku.com/v_show/id_XNTgxMDQ2OTc2MA==.html?spm=a2hcb.playlsit.page.1
驴友花雕
发表于 2021-10-1 15:59:27
实验场景图 动态图
驴友花雕
发表于 2021-11-22 16:20:21
【花雕动手做】有趣好玩的音乐可视化系列小项目
项目之四:FFT算法的双点阵屏的动态频谱仪
实验视频剪辑
https://v.youku.com/v_show/id_XNTgyMjEwNjcwMA==.html?spm=a2hcb.playlsit.page.1
https://v.youku.com/v_show/id_XNTgyMjEwNjcwMA==.html?spm=a2hcb.playlsit.page.1
驴友花雕
发表于 2021-11-22 16:33:12
实验场景动态图
阳老师
发表于 2021-11-25 14:55:19
驴友花雕 发表于 2021-7-1 12:04
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十六:6mm大尺寸8x8L ...
太好了,学习学习
驴友花雕
发表于 2021-11-25 20:54:46
阳老师 发表于 2021-11-25 14:55
太好了,学习学习
谢谢阳老师的鼓励