Yep, thanks! This was just a temporary test to see if it would work at all. I already rewrote the code, played a game of Centipede using a quarter and a start button, and got my second highest score so far. Here is the final version:
#include <Keyboard.h> //Including the keyboard library
//Declaring variables for the pins
int StartA = 2; // Orange
int StartB = 3; // Brown
int StartC = 4; // Gray
int StartD = 5; // Purple
int CoinB = 6; // Yellow
int CoinA = 7; // Blue
int CoinC = 8; // Future
int CoinD = 9; // Future
bool PrStartA = 0; // Last state of button press
bool PrStartB = 0;
bool PrStartC = 0;
bool PrStartD = 0;
bool PrCoinA = 0;
bool PrCoinB = 0;
bool PrCoinC = 0;
bool PrCoinD = 0;
void setup() {
pinMode(StartA, INPUT_PULLUP); //Setting up the internal pull-ups resistors
pinMode(StartB, INPUT_PULLUP); //and also setting the pins to inputs.
pinMode(StartC, INPUT_PULLUP);
pinMode(StartD, INPUT_PULLUP);
pinMode(CoinA, INPUT_PULLUP);
pinMode(CoinB, INPUT_PULLUP);
pinMode(CoinC, INPUT_PULLUP);
pinMode(CoinD, INPUT_PULLUP);
}
void loop() {
if (digitalRead(StartA) == LOW) //If the button is currently pressed
{
if (PrStartA == 0) // Will be 0 one time at the beginning of the button press
{
PrStartA = 1; // The button is pressed until it isn't
Keyboard.press('1'); // Send the keyboard press signal one time until it is eventually released
delay(3); // Prevent triple typing on first press
}
} else // The button is not currently pressed
{
if (PrStartA == 1) // Will be 1 one time at the end of the button press
{
PrStartA = 0; // The button is released until it is eventually pressed again
Keyboard.release('1'); // Send the keyboard release signal one time until it is eventually pressed again
}
}
if (digitalRead(StartB) == LOW) //If the button is currently pressed
{
if (PrStartB == 0) // Will be 0 one time at the beginning of the button press
{
PrStartB = 1; // The button is pressed until it isn't
Keyboard.press('2'); // Send the keyboard press signal one time until it is eventually released
delay(3); // Prevent triple typing on first press
}
} else // The button is not currently pressed
{
if (PrStartB == 1) // Will be 1 one time at the end of the button press
{
PrStartB = 0; // The button is released until it is eventually pressed again
Keyboard.release('2'); // Send the keyboard release signal one time until it is eventually pressed again
}
}
if (digitalRead(StartC) == LOW) //If the button is currently pressed
{
if (PrStartC == 0) // Will be 0 one time at the beginning of the button press
{
PrStartC = 1; // The button is pressed until it isn't
Keyboard.press('3'); // Send the keyboard press signal one time until it is eventually released
delay(3); // Prevent triple typing on first press
}
} else // The button is not currently pressed
{
if (PrStartC == 1) // Will be 1 one time at the end of the button press
{
PrStartC = 0; // The button is released until it is eventually pressed again
Keyboard.release('3'); // Send the keyboard release signal one time until it is eventually pressed again
}
}
if (digitalRead(StartD) == LOW) //If the button is currently pressed
{
if (PrStartD == 0) // Will be 0 one time at the beginning of the button press
{
PrStartD = 1; // The button is pressed until it isn't
Keyboard.press('4'); // Send the keyboard press signal one time until it is eventually released
delay(3); // Prevent triple typing on first press
}
} else // The button is not currently pressed
{
if (PrStartD == 1) // Will be 1 one time at the end of the button press
{
PrStartD = 0; // The button is released until it is eventually pressed again
Keyboard.release('4'); // Send the keyboard release signal one time until it is eventually pressed again
}
}
if (digitalRead(CoinA) == LOW) //If the button is currently pressed
{
if (PrCoinA == 0) // Will be 0 one time at the beginning of the button press
{
PrCoinA = 1; // The button is pressed until it isn't
Keyboard.press('5'); // Send the keyboard press signal one time until it is eventually released
delay(3); // Prevent triple typing on first press
}
} else // The button is not currently pressed
{
if (PrCoinA == 1) // Will be 1 one time at the end of the button press
{
PrCoinA = 0; // The button is released until it is eventually pressed again
Keyboard.release('5'); // Send the keyboard release signal one time until it is eventually pressed again
}
}
if (digitalRead(CoinB) == LOW) //If the button is currently pressed
{
if (PrCoinB == 0) // Will be 0 one time at the beginning of the button press
{
PrCoinB = 1; // The button is pressed until it isn't
Keyboard.press('6'); // Send the keyboard press signal one time until it is eventually released
delay(3); // Prevent triple typing on first press
}
} else // The button is not currently pressed
{
if (PrCoinB == 1) // Will be 1 one time at the end of the button press
{
PrCoinB = 0; // The button is released until it is eventually pressed again
Keyboard.release('6'); // Send the keyboard release signal one time until it is eventually pressed again
}
}
if (digitalRead(CoinC) == LOW) //If the button is currently pressed
{
if (PrCoinC == 0) // Will be 0 one time at the beginning of the button press
{
PrCoinC = 1; // The button is pressed until it isn't
Keyboard.press('7'); // Send the keyboard press signal one time until it is eventually released
delay(3); // Prevent triple typing on first press
}
} else // The button is not currently pressed
{
if (PrCoinC == 1) // Will be 1 one time at the end of the button press
{
PrCoinC = 0; // The button is released until it is eventually pressed again
Keyboard.release('7'); // Send the keyboard release signal one time until it is eventually pressed again
}
}
if (digitalRead(CoinD) == LOW) //If the button is currently pressed
{
if (PrCoinD == 0) // Will be 0 one time at the beginning of the button press
{
PrCoinD = 1; // The button is pressed until it isn't
Keyboard.press('8'); // Send the keyboard press signal one time until it is eventually released
delay(3); // Prevent triple typing on first press
}
} else // The button is not currently pressed
{
if (PrCoinD == 1) // Will be 1 one time at the end of the button press
{
PrCoinD = 0; // The button is released until it is eventually pressed again
Keyboard.release('8'); // Send the keyboard release signal one time until it is eventually pressed again
}
}
}