ocrobot:alpha:kitone:tutorial10
差别
这里会显示出您选择的修订版和当前版本之间的差别。
| 两侧同时换到之前的修订记录前一修订版 | |||
| ocrobot:alpha:kitone:tutorial10 [2019/07/15 02:31] – 董凯萍 | ocrobot:alpha:kitone:tutorial10 [2025/10/11 02:55] (当前版本) – 外部编辑 127.0.0.1 | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ~~NOTOC~~ | ||
| + | ====== Button(按键) ====== | ||
| + | <WRAP left round info 100%> | ||
| + | 当你按下按键的时候会接通电路的两点。这个例子是当你按下按键的时候点亮连接在12号脚上的LED。 | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== ALPHA MEGA328-U核心 ===== | ||
| + | ==== 硬件 ==== | ||
| + | * [[ocrobot: | ||
| + | * [[ocrobot: | ||
| + | * [[ocrobot: | ||
| + | * [[ocrobot: | ||
| + | ==== 搭建电路 ==== | ||
| + | |||
| + | - ALPHA MEGA328-U模块插入并行扩展版1号槽位。 | ||
| + | - ALPHA 11 LED模块插入1号槽位,堆叠于MEGA328-U上。 | ||
| + | - ALPHA 微动开关模块插入并行扩展板2号槽位。 | ||
| + | - USB线连接计算机与ALPHA MEGA328-U。 | ||
| + | {{ocrobot: | ||
| + | ==== 代码 ==== | ||
| + | |||
| + | <code cpp> | ||
| + | /* | ||
| + | Button | ||
| + | 按下连结在15号脚的按键之后,让LED亮灭 | ||
| + | */ | ||
| + | const int buttonPin = 15; // | ||
| + | const int ledPin = 2; // LED脚 | ||
| + | |||
| + | int buttonState = 0; // 按键状态的变量 | ||
| + | |||
| + | void setup() { | ||
| + | pinMode(ledPin, | ||
| + | pinMode(buttonPin, | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | buttonState = digitalRead(buttonPin); | ||
| + | if (buttonState == HIGH) { // 检查按键是否被按下. | ||
| + | digitalWrite(ledPin, | ||
| + | } | ||
| + | else { | ||
| + | digitalWrite(ledPin, | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | [[ocrobot: | ||
