/* Firmware for OSU! Keyboard. On arduino pro micro and clones, connect switches to GND and then A3 and A2, nothing else needed: GND ---+--- SW1 ---- A3 | +--- SW2 ---- A2 The debounce cooldown value should be set after flashing. Set it by holding down both buttons when plugging in the keyboard, wait 2 seconds, then connect to the USB serial port with minicom or putty. Try a value of 100 to begin with, then try pressing the keys and check that only one keystroke is sent per press. If some presses result in more than one keypress, increase the value, try adding 50 each time. This amazing software program is released under WTFPL in 2021 by Jimmy Christensen. */ #include "Keyboard.h" #include const int BTNA = 21; const int BTNB = 20; uint16_t cooldown = 100; int lasta; int lastb; uint16_t coola=0; uint16_t coolb=0; void setup() { delay(2000); pinMode(BTNA, INPUT); digitalWrite(BTNA, HIGH); pinMode(BTNB, INPUT); digitalWrite(BTNB, HIGH); lasta=0; lastb=0; int val = EEPROM[0]; cooldown = val; val = EEPROM[1]; cooldown += (val <<8); if( !digitalRead(BTNA) && !digitalRead(BTNB)) { Serial.begin(9600); Serial.println("OSU! Keys v 0, by DST"); Serial.println(" Config:"); Serial.print(" Debounce loops: "); Serial.println(cooldown); Serial.println("[S]et new value or [Q]uit ?"); bool quit=0; char str[16]; while(!quit) { if(Serial.available()) { unsigned char k = Serial.read(); if( k == 'q') { Serial.println("Okay, bye bye."); quit = 1; } if( k == 's') { Serial.print("New value (between 0 and 65535): "); val=0; while(!quit) { if(Serial.available()) { k = Serial.read(); if(k == '\r') { if(val) { cooldown = (uint16_t)atol(str); Serial.println(""); Serial.println("Setting debounce loops to "); Serial.println(cooldown); Serial.println("Saving.."); EEPROM[0] = cooldown & 0xFF; EEPROM[1] = (cooldown >> 8) & 0xFF; Serial.println("Saved."); quit=1; } else { Serial.println("Not setting anything.."); } quit=1; } else if(k > '0'-1 && k < '9'+1){ str[val]=k; str[val+1]=0; if(val > 5) { Serial.println("Invalid value..:"); quit=1; } else { Serial.print((char)k); } val++; } } } } } } Serial.println("Serial connection close, starting keyboard mode..."); Serial.end(); } Keyboard.begin(); } void loop() { int a = digitalRead(BTNA); int b = digitalRead(BTNB); if(coola >0) { coola--; } if(!a && lasta && !coola) { Keyboard.press('z'); lasta=0; coola = cooldown; } if(a && !lasta && !coola) { Keyboard.release('z'); lasta=1; } if(coolb > 0) { coolb--; } if(!b && lastb && !coolb) { Keyboard.press('x'); lastb=0; coolb = cooldown; } if(b && !lastb && !coolb) { Keyboard.release('x'); lastb=1; } }