智能家居自动化硬件测试与代码实现
立即解锁
发布时间: 2025-08-21 00:15:10 阅读量: 1 订阅数: 4 


英特尔Galileo开发实战指南
# 智能家居自动化硬件测试与代码实现
## 1. 键盘测试
### 1.1 键盘功能
- **系统状态**:启动系统后处于锁定状态,若 PIR 传感器检测到移动会发送警报。输入正确 PIN 码可解锁系统,再次输入相同 PIN 码则重新锁定。
- **LED 指示**:绿色 LED 亮起表示系统锁定,熄灭表示解锁。每次按键,LED 会闪烁 500ms 确认按键被系统识别。
- **特殊按键功能**:按下“#”键用于确认 PIN 码;按下“*”键可重置已输入的数字,允许用户重新输入。
### 1.2 键盘连接
| 键盘部分 | 对应连接引脚 |
| ---- | ---- |
| 行 0 - 3 | 连接器引脚 1 - 4 |
| 列 0 - 2 | 连接器引脚 5 - 7 |
这些引脚需连接到 Intel Galileo 数字端口,可通过软件轻松自定义。LED 可连接到数字端口 13,内置 LED 也连接到该引脚,可选择是否使用外部 LED。
### 1.3 键盘软件编写与测试
#### 1.3.1 操作步骤
1. 从 http://playground.arduino.cc/Code/Keypad 下载 Keypad 库。
2. 定位 Arduino IDE 安装目录下的“libraries”文件夹,例如:c:\arduino - 1.5.3 - windows\arduino - 1.5.3\libraries。
3. 解压 ZIP 文件,确保库文件与其他库处于同一级别。
4. 打开 keypad_testcode.ino 并运行,按 CTRL + SHIFT + M 打开串口控制台调试器。
#### 1.3.2 代码示例
```cpp
#include <Keypad.h>
enum SYSTEM_STATUS{
LOCKED, // 0
UNLOCKED, // 1
};
static SYSTEM_STATUS currentStatus = LOCKED;
const String password = "1968";
String input;
const byte ledPin = 12;
const byte ROWS = 4; // four rows
const byte COLS = 3; // three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; // pins on Intel Galielo I/O
byte colPins[COLS] = {8, 7, 6}; // pins on Intel Galielo I/O
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(115200);
// in case there is an LED CONNECTED
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH); // The default is system locked..
// so, the LED must be HIGH
keypad.addEventListener(handleKey); // this is the listener to handle
// the keys
}
void loop(){
// reading the keyboard
char key = keypad.getKey();
// if it’s a valid key
if (key) {
if ((key != '#') && (key != '*'))
{
input += key;
}
Serial.print("key:");
Serial.println(key);
}
}
// this function is only called when the PIN code
// typed matches the secret PIN code and inverts
// the system logic. It means if the system was LOCKED
// it will be UNLOCKED and vice versa.
void updateLEDStatus() {
if (currentStatus == LOCKED)
{
currentStatus = UNLOCKED;
Serial.println("SYSTEM UNLOCKED");
// turn OFF the LED
digitalWrite(ledPin, LOW);
}
else
```
0
0
复制全文
相关推荐










