I'm writing a code for my Leonardo, so that if the right wire from a bomb prop is pulled, it transitions a slide on the computer its connected to (done by pressing 6 then ENTER) and conversely if wrong wire pulled / goes HIGH it sends the command 4 then ENTER...
I tried using the BOOLEAN condition of game_complete to update the condition once one of this statements was performed but it just continually repeats the key command, rather than just entering it once...
Is there a fault in my code or can Arduino simply not perform this function in this way?
code below:
`#include <Keyboard.h>
void setup() {
// put your setup code here, to run once:
boolean game_complete = false;
}
void loop() {
// put your main code here, to run repeatedly:
pinMode (9,INPUT_PULLUP);
pinMode (8,INPUT_PULLUP);
pinMode (7,INPUT_PULLUP);
pinMode (6,OUTPUT);
int right_wire = 9;
int wrong_wire = 8;
int big_red_button = 7;
boolean game_complete;
if(game_complete == false){
//here it will transition slide by pressing "enter" when the red button is pressed which will reveal the wire to pull.
if (digitalRead(big_red_button)==LOW){
Keyboard.press(KEY_RETURN);
delay(100);
Keyboard.releaseAll();
delay(5000);
}
//if the correct wire is pulled, then the following will occur
else if(digitalRead(right_wire)==HIGH){
// press number then enter here "54" is the code for the number 5
//this will press "6" then the "enter" key
Keyboard.press(54);
delay(100);
Keyboard.press(KEY_RETURN);
delay(100);
Keyboard.releaseAll();
delay(1000);
game_complete = true;
}
//if the wrong wire is removed, then the following will occur
else if (digitalRead(wrong_wire)==HIGH){
// press number then enter here "52" is the code for the number 4
//this will press "4" then the "enter" key
Keyboard.press(52);
delay(100);
Keyboard.press(KEY_RETURN);
delay(100);
Keyboard.releaseAll();
delay(1000);
game_complete = true;
}
}
}`