“欧姆龙按键开关模块”的版本间的差异

来自YFRobotwiki
跳转至: 导航搜索
应用示例
 
(未显示1个用户的8个中间版本)
第37行: 第37行:
 
=== 应用示例 ===
 
=== 应用示例 ===
 
<br><br>
 
<br><br>
<font color="darkcyan">'''示例一'''</font>: 电位器 制[http://www.yfrobot.com/wiki/index.php?title=%E5%BD%A9%E8%89%B2LED%E6%A8%A1%E5%9D%97 彩色LED模块]变色
+
<font color="darkcyan">'''示例一'''</font>: 按键 制LED
 
<br>
 
<br>
  
 
:'''电路连接'''
 
:'''电路连接'''
 
<br>
 
<br>
::'''欧姆龙按键模块'''的 G、V、S分别连接 '''Arduino UNO'''的GND、VCC(+5V) 、D8~D12 引脚。
+
::'''欧姆龙按键模块'''的 G、V、S分别连接 '''Arduino UNO'''的GND、VCC(+5V) 、D2 引脚。
::''' 无源蜂鸣器 模块'''的 G、V、S分别连接 '''Arduino UNO'''的GND、VCC(+5V) 、D6 引脚。
+
::''' 食人鱼LED 模块'''的 G、V、S分别连接 '''Arduino UNO'''的GND、VCC(+5V) 、D10 引脚。
  
 
<br>
 
<br>
 
:'''电路连接示意图'''
 
:'''电路连接示意图'''
<img src="http://yfrobot.gitee.io/pic/wiki/按 控制LED.png"  alt="按 控制LED" />
+
<img src="http://yfrobot.gitee.io/wiki/img/按 控制LED.png"  alt="按 控制LED" />
 
+
  
  
 
:'''示例代码'''
 
:'''示例代码'''
 +
<source lang="c">
 +
/*
 +
  Button_switch
 +
  按键开关:按一次按键,点亮LED,再按一次按键,熄灭LED
 +
  This example code is in the public domain.
 +
  www.yfrobot.com
 +
*/
 +
 +
// constants won't change. They're used here to set pin numbers:
 +
const int buttonPin = 2;    // the number of the pushbutton pin
 +
const int ledPin =  10;      // the number of the LED pin
 +
boolean ledState = false;    // 记录LED状态
 +
boolean buttonState = true;  // 记录按键状态
 +
 +
void setup ()
 +
{
 +
  pinMode(buttonPin, INPUT_PULLUP);
 +
  pinMode(ledPin, OUTPUT);
 +
}
 +
 +
void loop()
 +
{
 +
  // read the state of the pushbutton value:
 +
  buttonState = digitalRead(buttonPin);
 +
 +
  // 等待按键按下
 +
  while (buttonState == HIGH) {
 +
    buttonState = digitalRead(buttonPin);
 +
  }
 +
  // 当按键按下时,点亮或熄灭LED
 +
  if (ledState == true) {
 +
    digitalWrite(ledPin, LOW);
 +
    ledState = !ledState;
 +
  } else {
 +
    digitalWrite(ledPin, HIGH);
 +
    ledState = !ledState;
 +
  }
 +
  delay(500);
 +
}
 +
</source>
 +
程序下载地址:[http://yfrobot.gitee.io/wiki/ino/ButtonTest.ino ButtonTest]
 +
 +
程序运行结果:按下一次按键,点亮LED,再按一次按键,熄灭LED。
  
  
第65行: 第107行:
 
<br>
 
<br>
 
:'''电路连接示意图'''
 
:'''电路连接示意图'''
<img src="http://yfrobot.gitee.io/pic/wiki/按钮控制无源蜂鸣器发声.png"  alt="按钮控制无源蜂鸣器发声" />
+
<img src="http://yfrobot.gitee.io/wiki/img/按钮控制无源蜂鸣器发声.png"  alt="按钮控制无源蜂鸣器发声" />
  
  
  
 
:'''示例代码'''
 
:'''示例代码'''
<pre >
+
<source lang="c">
 
//button test
 
//button test
  
第110行: 第152行:
 
   noTone(buzzerPin);
 
   noTone(buzzerPin);
 
}
 
}
</pre>
+
</source>
 
 程序下载地址:[https://eyun.baidu.com/s/3skMXhbn buttonTest]
 
 程序下载地址:[https://eyun.baidu.com/s/3skMXhbn buttonTest]
  
第116行: 第158行:
  
 
 程序演示视频:[https://eyun.baidu.com/s/3qY0oIQw button]
 
 程序演示视频:[https://eyun.baidu.com/s/3qY0oIQw button]
 +
 +
 +
 +
  
 
===参考资料===
 
===参考资料===

2021年2月20日 (六) 09:52的最后版本

生成缩略图出错:文件可能丢失:
按键模块


产品简介


欧姆龙按键模块采用原装进口欧姆龙轻触式按键设计制作。欧姆龙按键具有轻快的按键触感,高品质寿命长。五色按键帽自由选择,外观大气美观。

欧姆龙按键模块按下时,输出低电平;释放时,输出高电平。

规格参数


  • 供电电压:DC3.3 - 5V
  • 工作温度:-25~+70℃,60%RH以下(无结冰、无凝露)
  • 工作湿度:35~85%RH(+5~+35℃)
  • 接点结构:1A常开接点
  • 接触阻值:100mΩ以下
  • 绝缘阻值:100MΩ以上
  • 使用寿命:1000万次以上
  • 安装孔径:3MM
  • 模块尺寸:28*21*15.8MM(长*宽*高)
  • 孔间距:15MM
  • 模块重量:3.8g



引脚说明


  • 1. G -- Gnd(地)
  • 2. V -- Vcc(电源+5V)
  • 3. S -- Sign(信号)


应用示例



示例一:按键控制LED

电路连接


欧姆龙按键模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、D2引脚。
食人鱼LED模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、D10引脚。


电路连接示意图

按键控制LED


示例代码
/*
  Button_switch
  按键开关:按一次按键,点亮LED,再按一次按键,熄灭LED
  This example code is in the public domain.
  www.yfrobot.com
*/
 
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  10;      // the number of the LED pin
boolean ledState = false;    // 记录LED状态
boolean buttonState = true;  // 记录按键状态
 
void setup ()
{
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}
 
void loop()
{
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
 
  // 等待按键按下
  while (buttonState == HIGH) {
    buttonState = digitalRead(buttonPin);
  }
  // 当按键按下时,点亮或熄灭LED
  if (ledState == true) {
    digitalWrite(ledPin, LOW);
    ledState = !ledState;
  } else {
    digitalWrite(ledPin, HIGH);
    ledState = !ledState;
  }
  delay(500);
}

程序下载地址:ButtonTest

程序运行结果:按下一次按键,点亮LED,再按一次按键,熄灭LED。




示例二:按键控制无源蜂鸣器发声

电路连接


5个欧姆龙按键模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、D8~D12引脚。
无源蜂鸣器模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、D6引脚。


电路连接示意图

按钮控制无源蜂鸣器发声


示例代码
//button test
 
int buzzerPin = 6;
int buttonPin[5] = {8,9,10,11,12};
int buttonState = 0;
int buttonVal[5];
 
int notes_DL[7] = {147,165,175,196,221,248,278};
int notes_D[7] = {294,330,350,399,441,495,556};
int notes_DH[7] = {589,667,700,786,882,990,1112};
 
void setup ()
{
  pinMode(buzzerPin,OUTPUT);  
}
 
void loop()
{
  for(int i = 0;i < 5;i++){
   if(digitalRead(buttonPin[i]) == LOW){
     buttonState = buttonPin[i];
   }
  }  
 switch(buttonState){
   case 8: makeSound(1); break;
   case 9: makeSound(2); break;
   case 10: makeSound(3); break;
   case 11: makeSound(4); break;
   case 12: makeSound(5); break;
 }
 buttonState = 0;
} 
 
// s value: 1 - 7 
void makeSound(int s){
  tone(buzzerPin,notes_D[s-1]);
  delay(400);
  noTone(buzzerPin);
}

程序下载地址:buttonTest

程序运行结果:每个按键,可以发一个音符,按下即可发声,分别 "dol re mi fa so" 。

程序演示视频:button



参考资料





返回首页

更多建议和问题欢迎反馈至 YFRobot论坛

购买方式:YFRobot 电子工作室