/** * Author: Kulverstukas * Date: 2016-11-15 * Website: 9v.lt * Description: * Simple program to send a keyboard key to the computer * using a keyboard controller upon button press. */ const int BUTTON_PIN = 3; const int LED_PIN = 2; const int KBD_25_PIN = 4; // 25th keyboard controller pin const int KBD_5_PIN = 5; // 5th keyboard controller pin, produces letter 'c' void setup() { // here we need to set both keyboard controller pins to INPUT // otherwise both pins would be connected and make a contact // so the controller would think that the button is constantly // pressed and send out a signal pinMode(KBD_25_PIN, INPUT); pinMode(KBD_5_PIN, INPUT); pinMode(LED_PIN, OUTPUT); pinMode(BUTTON_PIN, INPUT); digitalWrite(BUTTON_PIN, HIGH); // we don't need a resistor if we do this } void loop() { int value = digitalRead(BUTTON_PIN); if (value == LOW) { digitalWrite(LED_PIN, HIGH); // connect both pins pinMode(KBD_25_PIN, OUTPUT); pinMode(KBD_5_PIN, OUTPUT); // we have to wait some time for the controller to register a button press // this is just enough to trigger once delay(100); pinMode(KBD_25_PIN, INPUT); pinMode(KBD_5_PIN, INPUT); // stop the spam delay(10000); digitalWrite(LED_PIN, LOW); } }