1. Uno板连接接收模块与发射模块
1.1接线说明
接收模块 Uno板
GND ------------GND接地线
VCC -------------5V接电源
数据引脚------11引脚(此例子接法)
发射模块 Uno板
GND ------------GND接地线
VCC -------------5V接电源
数据引脚------12引脚(此例子接法)
1.2测试代码
接收模块代码:
#include <VirtualWire.h> #undef int #undef abs #undef double #undef float #undef round
byte buf[VW_MAX_MESSAGE_LEN]; byte buflen = VW_MAX_MESSAGE_LEN; void setup() { Serial.begin(9600); // Debugging only Serial.println("setup"); Serial.println("Receiver..."); // Initialise the IO and ISR vw_set_ptt_inverted(true); // Required for DR3100 vw_setup(2000); // Bits per sec vw_rx_start(); // Start the receiver PLL running } void loop() {
if (vw_get_message(buf, &buflen))//Non-blocking { int i; digitalWrite(12, true); //Flash a light to show received good message Serial.print("Got: "); //Message with a good checksum received, dump it. for (i = 0; i < buflen; i++) { Serial.print(buf[i], HEX); Serial.print(" "); } Serial.println(""); digitalWrite(12, false); } }
|
发射模块代码:
#include <VirtualWire.h> #undef int #undef abs #undef double #undef float #undef round void setup() { Serial.begin(9600); // Debugging only Serial.println("setup"); Serial.println("Transmmiter..."); // Initialise the IO and ISR vw_set_ptt_inverted(true); // Required for DR3100 vw_setup(2000); // Bits per sec } void loop() { const char *msg = "hello"; digitalWrite(13, true); // Flash a light to show transmitting vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); // Wait until the whole message is gone digitalWrite(13, false); delay(200); }
|
2. Uno板连接显示器
2.1 接线说明
2.2 测试代码
2.2.1英文显示屏测试代码
//LingShun lab #include <Wire.h> #include <LiquidCrystal_I2C.h> //引用I2C库
//设置LCD1602设备地址,这里的地址是0x3F,一般是0x20,或者0x27,具体看模块手册 LiquidCrystal_I2C lcd(0x3F,16,2);
void setup() { lcd.init(); // 初始化LCD lcd.backlight(); //设置LCD背景等亮 }
void loop() { lcd.setCursor(0,0); //设置显示指针 lcd.print("Hello Wzx!!!"); //输出字符到LCD1602上 int ButtonState = digitalRead(0); //设置变量存储读到的状态值 //lcd.clear(); delay(1000); }
|
2.2.2中文显示屏测试代码
#include <RSCG12864B.h>//引用库文件 void setup() { void loop() {
|