/**
Project template for TV Pong - The final project of the Raspberry Pi Pico (RP2040) Deep Dive Course.
https://hackaday.io/project/180374-pi-pico-pal-tv-pong
Good luck!
*/
const int player1Up = 4;
const int player1Down = 5;
const int player2Up = 6;
const int player2Down = 7;
void setup() {
Serial1.begin(115200);
Serial1.println("The game begins...");
pinMode(player1Up, INPUT_PULLUP);
pinMode(player1Down, INPUT_PULLUP);
pinMode(player2Up, INPUT_PULLUP);
pinMode(player2Down, INPUT_PULLUP);
}
void checkInput(int pin, String keyName) {
if (!digitalRead(pin)) {
Serial1.println(keyName);
delay(200); // poor man's debouncing
}
}
void loop() {
checkInput(player1Up, "Player1: Up");
checkInput(player1Down, "Player1: Down");
checkInput(player2Up, "Player2: Up");
checkInput(player2Down, "Player2: Down");
delay(1); // This really speeds up the simulation in accurate clock mode
}