Press USER_BUTTON0 to light up the LED.

ボタンを押している間だけ何かしらの処理をしたいときのためのメモ用プログラム(モーメンタリ動作というらしい)

USER_BUTTON0を押している間だけLEDが光ります。

Files at this revision

API Documentation at this revision

Comitter:
knzw
Date:
Sun Sep 15 07:21:09 2019 +0000
Commit message:
Press USER_BUTTON0 to light up the LED.

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Sun Sep 15 07:21:09 2019 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Sep 15 07:21:09 2019 +0000
@@ -0,0 +1,47 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2018 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/* ボタン押している間なにかする処理のサンプルプログラム的な(モーメンタリ動作というらしい) */
+#include "mbed.h"
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+#define SLEEP_TIME                  500 // (msec)
+#define PRINT_AFTER_N_LOOPS         20
+
+static InterruptIn btn0(USER_BUTTON0);
+static bool btndownflg=false; //falseのとき、ボタンを離している
+
+void btnfall0(void){
+  btndownflg=true;//ボタンおした
+}
+
+void btnrise0(void){
+  btndownflg=false;//ボタンはなれた
+}
+
+
+int main(){
+
+  btn0.fall(&btnfall0); //ボタンを押したときに関数btnfall0を呼び出す
+  btn0.rise(&btnrise0); //ボタンを離したときに関数をbtnrise0を呼び出す
+
+    while (true) {
+      if(btndownflg){
+        led1=true;
+        led2=true;
+        led3=true;
+        led4=true;
+      }else{
+        led1=false;
+        led2=false;
+        led3=false;
+        led4=false;
+      }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sun Sep 15 07:21:09 2019 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#5941d1718339116cd12914238ec331c84da3d08f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Sun Sep 15 07:21:09 2019 +0000
@@ -0,0 +1,11 @@
+{
+    "target_overrides": {
+        "*": {
+            "platform.stack-stats-enabled": true,
+            "platform.heap-stats-enabled": true,
+            "platform.cpu-stats-enabled": true,
+            "platform.thread-stats-enabled": true,
+            "platform.sys-stats-enabled": true
+        }
+    }
+}