Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:36046ae1c65e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 28 15:10:02 2016 +0000 @@ -0,0 +1,56 @@ +#include "mbed.h" + +// タイミング調整(秒) +#define LEVER_INTERVAL 5.0 // 1プレイの周期(4.1以上。演出みたいのですこし長めにしてます) +#define LEVER_BUTON_INTERVAL 1.0 // レバーとボタンの間 +#define BUTTON_ON_PERIOD 0.1 // ボタン押している時間 +#define BUTTON_INTERVAL 0.2 // ボタン間隔 + + +// ボタン、レバーのピン番号は各自自分の環境に修正が必要 +DigitalOut lever(D2); +DigitalOut left_button(D3); +DigitalOut centor_button(D4); +DigitalOut right_button(D5); + +// NUCLEO-F401RE用 +DigitalOut myled(LED1); +InterruptIn button(USER_BUTTON); + +int autoplay_en; // オートプレイ有効フラグ + +void switch_mode() +{ + autoplay_en = !autoplay_en; // 有効無効切り替え + myled = autoplay_en; // LEDトグル +} + +void push(DigitalOut dout){ + dout = 1; // おす + wait(BUTTON_ON_PERIOD); + dout = 0; // もどす +} + +int main() { + + button.fall(switch_mode); // 割り込み登録 + + // 初期値設定 + autoplay_en = 1; + myled = autoplay_en; + double last_wait = LEVER_INTERVAL - LEVER_BUTON_INTERVAL - 2*BUTTON_INTERVAL - 4 * BUTTON_ON_PERIOD; + + while(1) { + if (autoplay_en) { + push(lever); + wait(LEVER_BUTON_INTERVAL); + push(left_button); + wait(BUTTON_INTERVAL); + push(centor_button); + wait(BUTTON_INTERVAL); + push(right_button); + wait(last_wait); + } + } +} + \ No newline at end of file