用户工具

站点工具


ocrobot:alpha:kitone:tutorial10

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
ocrobot:alpha:kitone:tutorial10 [2019/07/15 02:31] 董凯萍ocrobot:alpha:kitone:tutorial10 [2023/06/07 04:23] (当前版本) – 外部编辑 127.0.0.1
行 1: 行 1:
 +~~NOTOC~~
 +====== Button(按键) ======
  
 +<WRAP left round info 100%>
 +当你按下按键的时候会接通电路的两点。这个例子是当你按下按键的时候点亮连接在12号脚上的LED。
 +</WRAP>
 +
 +
 +===== ALPHA MEGA328-U核心 =====
 +==== 硬件 ====
 +  * [[ocrobot:alpha:parallelexpansion:index|ALPHA 并行扩展板]]
 +  * [[ocrobot:alpha:mega328-u:main|ALPHA MEGA328-U]]
 +  * [[ocrobot:alpha:microswitch:index|ALPHA 微动开关模块]]
 +  * [[ocrobot:alpha:11led:index|ALPHA 11 LED模块]]
 +==== 搭建电路 ====
 +
 +  - ALPHA MEGA328-U模块插入并行扩展版1号槽位。
 +  - ALPHA 11 LED模块插入1号槽位,堆叠于MEGA328-U上。
 +  - ALPHA 微动开关模块插入并行扩展板2号槽位。
 +  - USB线连接计算机与ALPHA MEGA328-U。
 +{{ocrobot:alpha:kitone:led_按键435.png?nolink|}}
 +==== 代码 ====
 +
 +<code cpp>
 +/*
 +  Button
 +  按下连结在15号脚的按键之后,让LED亮灭
 +*/
 +const int buttonPin = 15;     //按键脚
 +const int ledPin =  2;      // LED脚
 +
 +int buttonState = 0;         // 按键状态的变量
 +
 +void setup() {
 +  pinMode(ledPin, OUTPUT);       // 初始化LED作为输出:
 +  pinMode(buttonPin, INPUT);     // 初始化按键作为输入:
 +}
 +
 +void loop() {
 +  buttonState = digitalRead(buttonPin);  // 读取按键值:
 +  if (buttonState == HIGH) {       // 检查按键是否被按下.  //如果是 buttonState就为high:
 +    digitalWrite(ledPin, HIGH);      // 点亮LED:
 +  }
 +  else {
 +    digitalWrite(ledPin, LOW);     // 熄灭LED:
 +  }
 +}
 +</code>
 +
 +[[ocrobot:alpha:kitone:main|返回上一级]]
ocrobot/alpha/kitone/tutorial10.txt · 最后更改: 2023/06/07 04:23 由 127.0.0.1