今天撥空弄了一個小玩具,就是可以用遙控器選擇顯示內容的點矩陣小螢幕
==
功能介紹:
利用遙控器,按下不同按鈕,即可切換不同的字串,顯示在矩陣螢幕上
硬體接法:
//-----HW setup----------
//IR接收器一個: VS1838B ,MAX7219 8x8 8
//--VS1838B-
//pin2: 連接 VS1838B OUT pin
//GND: 連接 VS1838B GND pin
//5V: 連接 VS1838B VCC pin
//-----MAX7219--SPI-------
//VCC: 5V
//GND: GND
//DOUT: Pin 11
//CS: Pin3
//CLK: Pin13
//---end of HW setup---
======
MD_parola API詳述:
https://majicdesigns.github.io/MD_Parola/class_m_d___parola.html
效果影片:
程式碼:
/* Example code for scrolling text effect on MAX7219 LED dot matrix display with Arduino. More info: https://www.makerguides.com */
#include <IRremote.h>
#include <IRremoteInt.h>
// Include the required Arduino libraries:
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
// Define hardware type, size, and output pins:
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 8 // how many 8x8 led combind
#define CS_PIN 3 // CS pin
//---IRremote key code
#define key_1 0xFF30CF
#define key_2 0xFF18E7
#define key_3 0xFF7A85
#define key_4 0xFF10EF
#define key_5 0xFF38C7
#define key_6 0xFF5AA5
// Create a new instance of the MD_Parola class with hardware SPI connection:
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Setup for software SPI:
// #define DATA_PIN 2
// #define CLK_PIN 4
// MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
//scrolling parameters
uint16_t scrollSpeed = 30;
uint16_t scrollPause = 2000;
textPosition_t scrollAlign = PA_CENTER;
textEffect_t scrollEffect = PA_SCROLL_LEFT;
#define BUF_SIZE 75
char key_1_Message[BUF_SIZE] = { "Work hard,play hard.Practice makes perfect." };
char key_2_Message[BUF_SIZE] = { "No pain,no gain.The first step is always the hardest." };
char key_3_Message[BUF_SIZE] = { "Winners do what losers do not want to do." };
char key_4_Message[BUF_SIZE] = { "Failure is the mother of success." };
char key_5_Message[BUF_SIZE] = { "Never underestimate your power to change yourself!" };
char key_6_Message[BUF_SIZE] = { "Never put off what you can do today until tomorrow." };
char newMessage[BUF_SIZE] = { "Hang on to your dreams." };
//---define for IRremote
const int irReceiverPin = 2;
IRrecv irrecv(irReceiverPin); // 初始化紅外線訊號輸入
decode_results results; // 儲存訊號的結構
//--
void ir_rec(){
if (irrecv.decode(&results)) { // 接收紅外線訊號並解碼
Serial.print("results value is "); // 輸出解碼後的資料
Serial.print(results.value, HEX);
Serial.print(", bits is ");
Serial.print(results.bits);
Serial.print(", decode_type is ");
Serial.println(results.decode_type);
switch(results.value){
case key_1:
Serial.println("case key_1 ");
strcpy(newMessage,key_1_Message);
myDisplay.displayClear();
myDisplay.displayReset();
break;
case key_2:
strcpy(newMessage,key_2_Message);
myDisplay.displayClear();
myDisplay.displayReset();
break;
case key_3:
strcpy(newMessage,key_3_Message);
myDisplay.displayClear();
myDisplay.displayReset();
break;
case key_4:
strcpy(newMessage,key_4_Message);
myDisplay.displayClear();
myDisplay.displayReset();
break;
case key_5:
strcpy(newMessage,key_5_Message);
myDisplay.displayClear();
myDisplay.displayReset();
break;
case key_6:
strcpy(newMessage,key_6_Message);
myDisplay.displayClear();
myDisplay.displayReset();
break;
}
irrecv.resume(); // 準備接收下一個訊號
}
}
void setup() {
Serial.begin(9600); // for Serial.print
irrecv.enableIRIn(); // 啟動接收
// Intialize the object:
myDisplay.begin();
// Set the intensity (brightness) of the display (0-15):
myDisplay.setIntensity(0);
// Clear the display:
myDisplay.displayClear();
//displayText (const char *pText, textPosition_t align, uint16_t speed, uint16_t pause, textEffect_t effectIn, textEffect_t effectOut=PA_NO_EFFECT)
myDisplay.displayText(newMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect , scrollEffect );
//displayScroll (const char *pText, textPosition_t align, textEffect_t effect, uint16_t speed)
//myDisplay.displayScroll("Mark,On Line!",PA_CENTER,PA_SCROLL_LEFT,50);
//myDisplay.setInvert(true);
}
void loop() {
ir_rec();
if (myDisplay.displayAnimate()) {
myDisplay.displayReset();
}
}
===
以上作紀錄,方便日後參考。
留言列表