OpenCR入门教程-开发示例-按钮
说明
- 本教程介绍OpenCR板上的内置按钮测试示例
代码
- OpenCR中有按键开关和拨动开关
//该代码以串行方式输出按钮的状态
#define BDPIN_DIP_SW_1 26
#define BDPIN_DIP_SW_2 27
#define BDPIN_PUSH_SW_1 34
#define BDPIN_PUSH_SW_2 35
void setup(){
Serial.begin(115200);
pinMode(BDPIN_DIP_SW_1, INPUT);
pinMode(BDPIN_DIP_SW_2, INPUT);
pinMode(BDPIN_PUSH_SW_1, INPUT);
pinMode(BDPIN_PUSH_SW_2, INPUT);
}
void loop(){
int dip_state;
int push_state;
dip_state = digitalRead(BDPIN_DIP_SW_1)<<0;
dip_state |= digitalRead(BDPIN_DIP_SW_2)<<1;
push_state = digitalRead(BDPIN_PUSH_SW_1)<<0;
push_state |= digitalRead(BDPIN_PUSH_SW_2)<<1;
Serial.print("dip_state = ");
Serial.print(dip_state, BIN);
Serial.print("\tpush_state = ");
Serial.println(push_state, BIN);
delay(100);
}
演示视频
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号