【雕爷学编程】Arduino动手做(163)---大尺寸8x8LED方格屏模块7
37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手试试多做实验,不管成功与否,都会记录下来——小小的进步或是搞不掂的问题,希望能够抛砖引玉。
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百六十三:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十:轮流显示数字 “1 - 9” 以及中文 “中”,“国”
实验开源代码
/* 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程) 实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度 项目三十:轮流显示数字 “1 - 9” 以及中文 “中”,“国” 接脚连线: MAX7219 UNO VCC →→→→→ 5V GND →→→→→ GND DIN →→→→→ D12(数据,数据接收引脚) CS →→→→→ D11(负载,命令接收引脚) CLK →→→→→ D10(时钟,时钟引脚) */ int clk = 10; int cs = 11; int din = 12; unsigned char disp1[12][8] = { {0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C}, //0 {0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08}, //1 {0x7E, 0x2, 0x2, 0x7E, 0x40, 0x40, 0x40, 0x7E}, //2 {0x3E, 0x2, 0x2, 0x3E, 0x2, 0x2, 0x3E, 0x0}, //3 {0x8, 0x18, 0x28, 0x48, 0xFE, 0x8, 0x8, 0x8}, //4 {0x3C, 0x20, 0x20, 0x3C, 0x4, 0x4, 0x3C, 0x0}, //5 {0x3C, 0x20, 0x20, 0x3C, 0x24, 0x24, 0x3C, 0x0}, //6 {0x3E, 0x22, 0x4, 0x8, 0x8, 0x8, 0x8, 0x8}, //7 {0x0, 0x3E, 0x22, 0x22, 0x3E, 0x22, 0x22, 0x3E}, //8 {0x3E, 0x22, 0x22, 0x3E, 0x2, 0x2, 0x2, 0x3E}, //9 {0x08, 0x7F, 0x49, 0x49, 0x7F, 0x08, 0x08, 0x08}, //中 {0xFE, 0xFE, 0x92, 0xFE, 0x9A, 0xFE, 0x82, 0xFE}, //国 }; void setup() { //设置引脚为输出 pinMode(cs, OUTPUT); pinMode(clk, OUTPUT); pinMode(din, OUTPUT); //初始化MAX7219 Init_MAX7219(); } void loop() { char i, j; //字体扫描显示 for (j = 0; j < 12; j++) { for (i = 1; i < 9; i++) { Write_Max7219(i, disp1[j][i - 1]); delay(20); } delay(50); } } void Write_Max7219_byte(char DATA) { char i; digitalWrite(cs, 0); for (i = 8; i >= 1; i--) { digitalWrite(clk, 0); if ((DATA & 0x80) > 0) { digitalWrite(din, 1); } else { digitalWrite(din, 0); } //提取最高位给DIN端口 DATA = DATA << 1; //左移一位 digitalWrite(clk, 1); } } void Write_Max7219(char address, char dat) { digitalWrite(cs, 0); Write_Max7219_byte(address); //写入地址,编号 Write_Max7219_byte(dat); //写入数据,即显示数字 digitalWrite(cs, 1); } void Init_MAX7219(void) { Write_Max7219(0x09, 0x00); //译码方式:BCD码 Write_Max7219(0x0a, 0x01); //亮度 Write_Max7219(0x0b, 0x07); //扫描界限;显示 Write_Max7219(0x0c, 0x01); //掉电模式:0,普通模式:1 Write_Max7219(0x0f, 0x00); delay(50); //显示测试:1;测试结束,正常显示:0 }
6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十:轮流显示数字 “1 - 9” 以及中文 “中”,“国”
实验场景图片
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); }
6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十一:使用Matrix库的三色LED
实验场景图片
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位置的数据。
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[10]; 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], 0); for (int i = 0; i < buffer[0] + 1; i++){ delay(shift_speed); m.shiftLeft(false, false); } } // 从文本字符串中提取字符 void printStringWithShift(char* s, int shift_speed) { while (*s != 0) { printCharWithShift(*s, shift_speed); s++; } }
6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十二:建立字母库,横式滚动文本显示(三级联)
实验场景图片
大小点阵屏的对比
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[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, 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[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(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; } }
实验场景图
6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
项目三十三:动态音乐频谱仪
实验视频剪辑
https://v.youku.com/v_show/id_XNTgxMDQ2OTc2MA==.html?spm=a2hcb.playlsit.page.1
项目:FFT算法的双点阵屏的动态频谱仪
实验视频剪辑
https://v.youku.com/v_show/id_XNTgyMjEwNjcwMA==.html?spm=a2hcb.playlsit.page.1
实验场景动态图