Micro:Bit กับ Arduino IDE #3 : ปุ่มกด

Thana Hongsuwan
1 min readNov 17, 2017

--

หลังจากแสดงผล LED Matrix กันไปแล้ว ต่อไปเราก็จะมารับข้อมูล Input กันบ้าง สำหรับบอร์ด Micro:Bit ก็จะมี 2 ปุ่ม คือ A กับ B ซึ่งอยู่ที่ขา 5 และ 11 ตามลำดับ ดังนั้นโปรแกรมก็เขียนง่ายๆ ดังนี้

const int PIN_BUTTON_A = 5;
const int PIN_BUTTON_A = 11;
void setup() {
Serial.begin(9600);
Serial.println("microbit is ready!");

pinMode(PIN_BUTTON_A, INPUT);
pinMode(PIN_BUTTON_B, INPUT);
}
void loop(){
if (! digitalRead(PIN_BUTTON_A)) {
Serial.println("Button A pressed");
}
if (! digitalRead(PIN_BUTTON_B)) {
Serial.println("Button B pressed");
}
delay(300);
}

เมื่อรันโปรแกรม และเปิด Serial Monitor จากนั้นกดปุ่ม ก็จะเห็นตามภาพ

สำหรับตอนนี้ก็ขอจบดื้อๆ สั้นๆ แต่เพียงเท่านี้

--

--

Thana Hongsuwan
Thana Hongsuwan

Written by Thana Hongsuwan

Maker สมัครเล่น สนใจเทคโนโลยีด้าน Hardware เช่น Arduino, ESP8266, ESP32, Internet of Things, Raspberry P, Deep Learning

No responses yet