Master Your Micro:bit with Arduino IDE--Button and Other GPIO
标签:DIY
LUCY 发布于 2018-01-20 12:25
In our previous blog Master Your Micro:bit with Arduino IDE ——Light LED, we have talked about how to install micro:bit library on Arduino IDE and how to drive LED on micro:bit with Arduino IDE. In this article, we are going to tell you how to drive micro:bit button and GPIO with Arduino IDE.
Microbit has two self-carried buttons on the board. We call it button A and button B separately. The corresponding IDE PIN for button A is 5 and the corresponding IDE PIN for button B is 11. You can see the circuit diagram for button below.
From this picture, we can see that the button has connected to pull-up resistance. Before the button is pressed, it is in high voltage. After the button is pressed, it is in low voltage. Here's the example code for the button:
[cceN_cpp theme="dawn"]
const int buttonA = 5; // the number of the pushbutton pin
const int buttonB = 11; // the number of the pushbutton pin
void setup() {
Serial.begin(9600);
Serial.println("microbit is ready!");
pinMode(buttonA, INPUT);
pinMode(buttonB, INPUT);
}
void loop(){
if (! digitalRead(buttonA)) {
Serial.println("Button A pressed");
}
if (! digitalRead(buttonB)) {
Serial.println("Button B pressed");
}
delay(10);
}
[/cceN_cpp]
After you downloaded the program, set the baud rate of Serial Monitar to be 9600.
Press button A, Serial Monitar will display "Button A pressed"; press button B,it will display "Button B pressed".
Micro:bit leads out partial IO port with its gold finger. We have to pay special attention to that most of IO port can be used repeatedly. To use these IO ports properly, you can refer to conditions of IO port repeat use. For more details, you can see the table below. This table shows various data about each of the pins on the micro:bit edge connector.
You can use aligator clip to lead out P0, P1, P3,3V and GND conveniently. If it is still not enough for you, I would like to recommend you to buy a micro:bit breakout board.
Both the above two breakout boards can lead out all of IO ports, which enable you to program for these IO ports and control the outer circuit.
Master Your Micro:bit with Arduino IDE ——Light LED
在淘宝中搜索“恩孚电子”,你可以以最优惠的价格购买到英国原装正版micro:bit哦!
如果想联系我们,请发邮件至:louise@elecfreaks.com 。
作者的最新作品
-
按钮
2018-05-31 17:05发布
-
用micro:bit让面包板上的两颗LED交替闪烁
2018-05-31 17:01发布
-
抛煎饼游戏
2018-05-18 18:33发布
-
micro:bit跑迷宫游戏
2018-05-18 18:29发布
-
速算游戏
2018-05-18 18:25发布
阅读数: 3987