tarui osakedaisuki
/
milkyslot_autoplay
DAXEL 探偵歌劇 ミルキィホームズTD 消えた7と奇跡の歌 の自動プレイ用プログラム
main.cpp@0:36046ae1c65e, 2016-11-28 (annotated)
- Committer:
- tarusake
- Date:
- Mon Nov 28 15:10:02 2016 +0000
- Revision:
- 0:36046ae1c65e
initial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tarusake | 0:36046ae1c65e | 1 | #include "mbed.h" |
tarusake | 0:36046ae1c65e | 2 | |
tarusake | 0:36046ae1c65e | 3 | // タイミング調整(秒) |
tarusake | 0:36046ae1c65e | 4 | #define LEVER_INTERVAL 5.0 // 1プレイの周期(4.1以上。演出みたいのですこし長めにしてます) |
tarusake | 0:36046ae1c65e | 5 | #define LEVER_BUTON_INTERVAL 1.0 // レバーとボタンの間 |
tarusake | 0:36046ae1c65e | 6 | #define BUTTON_ON_PERIOD 0.1 // ボタン押している時間 |
tarusake | 0:36046ae1c65e | 7 | #define BUTTON_INTERVAL 0.2 // ボタン間隔 |
tarusake | 0:36046ae1c65e | 8 | |
tarusake | 0:36046ae1c65e | 9 | |
tarusake | 0:36046ae1c65e | 10 | // ボタン、レバーのピン番号は各自自分の環境に修正が必要 |
tarusake | 0:36046ae1c65e | 11 | DigitalOut lever(D2); |
tarusake | 0:36046ae1c65e | 12 | DigitalOut left_button(D3); |
tarusake | 0:36046ae1c65e | 13 | DigitalOut centor_button(D4); |
tarusake | 0:36046ae1c65e | 14 | DigitalOut right_button(D5); |
tarusake | 0:36046ae1c65e | 15 | |
tarusake | 0:36046ae1c65e | 16 | // NUCLEO-F401RE用 |
tarusake | 0:36046ae1c65e | 17 | DigitalOut myled(LED1); |
tarusake | 0:36046ae1c65e | 18 | InterruptIn button(USER_BUTTON); |
tarusake | 0:36046ae1c65e | 19 | |
tarusake | 0:36046ae1c65e | 20 | int autoplay_en; // オートプレイ有効フラグ |
tarusake | 0:36046ae1c65e | 21 | |
tarusake | 0:36046ae1c65e | 22 | void switch_mode() |
tarusake | 0:36046ae1c65e | 23 | { |
tarusake | 0:36046ae1c65e | 24 | autoplay_en = !autoplay_en; // 有効無効切り替え |
tarusake | 0:36046ae1c65e | 25 | myled = autoplay_en; // LEDトグル |
tarusake | 0:36046ae1c65e | 26 | } |
tarusake | 0:36046ae1c65e | 27 | |
tarusake | 0:36046ae1c65e | 28 | void push(DigitalOut dout){ |
tarusake | 0:36046ae1c65e | 29 | dout = 1; // おす |
tarusake | 0:36046ae1c65e | 30 | wait(BUTTON_ON_PERIOD); |
tarusake | 0:36046ae1c65e | 31 | dout = 0; // もどす |
tarusake | 0:36046ae1c65e | 32 | } |
tarusake | 0:36046ae1c65e | 33 | |
tarusake | 0:36046ae1c65e | 34 | int main() { |
tarusake | 0:36046ae1c65e | 35 | |
tarusake | 0:36046ae1c65e | 36 | button.fall(switch_mode); // 割り込み登録 |
tarusake | 0:36046ae1c65e | 37 | |
tarusake | 0:36046ae1c65e | 38 | // 初期値設定 |
tarusake | 0:36046ae1c65e | 39 | autoplay_en = 1; |
tarusake | 0:36046ae1c65e | 40 | myled = autoplay_en; |
tarusake | 0:36046ae1c65e | 41 | double last_wait = LEVER_INTERVAL - LEVER_BUTON_INTERVAL - 2*BUTTON_INTERVAL - 4 * BUTTON_ON_PERIOD; |
tarusake | 0:36046ae1c65e | 42 | |
tarusake | 0:36046ae1c65e | 43 | while(1) { |
tarusake | 0:36046ae1c65e | 44 | if (autoplay_en) { |
tarusake | 0:36046ae1c65e | 45 | push(lever); |
tarusake | 0:36046ae1c65e | 46 | wait(LEVER_BUTON_INTERVAL); |
tarusake | 0:36046ae1c65e | 47 | push(left_button); |
tarusake | 0:36046ae1c65e | 48 | wait(BUTTON_INTERVAL); |
tarusake | 0:36046ae1c65e | 49 | push(centor_button); |
tarusake | 0:36046ae1c65e | 50 | wait(BUTTON_INTERVAL); |
tarusake | 0:36046ae1c65e | 51 | push(right_button); |
tarusake | 0:36046ae1c65e | 52 | wait(last_wait); |
tarusake | 0:36046ae1c65e | 53 | } |
tarusake | 0:36046ae1c65e | 54 | } |
tarusake | 0:36046ae1c65e | 55 | } |
tarusake | 0:36046ae1c65e | 56 |