From c82c75997c4fee5addb14f7f5fcd20b70257482a Mon Sep 17 00:00:00 2001 From: sirrow Date: Tue, 8 Sep 2020 20:24:36 +0900 Subject: [PATCH] add button for rapid fire --- connect_switch.ino | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/connect_switch.ino b/connect_switch.ino index edd5352..8f92e70 100644 --- a/connect_switch.ino +++ b/connect_switch.ino @@ -6,14 +6,18 @@ int state = 0; int table[40] = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int index = 0; -void perms() { - if (table[index] == 1){ - SwitchControlLibrary().PressButtonA(); - } - if (table[index] == 2){ - SwitchControlLibrary().ReleaseButtonA(); - } +int val = 1; +int prevVal = 1; +void perms() { + if(val == 0){ + if (table[index] == 1){ + SwitchControlLibrary().PressButtonA(); + } + if (table[index] == 2){ + SwitchControlLibrary().ReleaseButtonA(); + } + } index = (index + 1) % 40; } /* @@ -34,11 +38,21 @@ void setup() SwitchControlLibrary(); MsTimer2::set(1, perms); MsTimer2::start(); + + pinMode(2, INPUT_PULLUP); + } void loop() { - - + val = digitalRead(2); + if(prevVal == 1 && val == 0){ + SwitchControlLibrary().PressButtonA(); + index = 1; + } + else if(val == 1){ + SwitchControlLibrary().ReleaseButtonA(); + } + prevVal = val; }