/* ShaytanBox.ino v0.5 Nano DCCDurino with CH340G */ // Define pins for the keys. #define KeyPrint 7 #define KeyRight 5 #define KeyDown 6 #define KeyLeft 4 #define KeyUp 3 #define LedGreen 9 #define LedRed 10 void setup() { Serial.begin(9600); init(KeyPrint); init(KeyRight); init(KeyDown); init(KeyLeft); init(KeyUp); pinMode(LedGreen, OUTPUT); pinMode(LedRed, OUTPUT); digitalWrite(LedRed, HIGH); } void loop() { test(KeyPrint, "\x01"); test(KeyRight, "\x02"); test(KeyDown, "\x04"); test(KeyLeft, "\x08"); test(KeyUp, "\x10"); } void init(int x){ pinMode(x, INPUT); digitalWrite(x, HIGH); } void test(int y, char* z){ if (digitalRead(y) == LOW) { delay(100); if (digitalRead(y) == LOW) { unsigned long t = millis() + 500; digitalWrite(LedGreen, HIGH); Serial.print("KEY"); Serial.print(z); Serial.write((byte)0x00); Serial.write((byte)0x00); Serial.println(); while((millis() < t ) && (digitalRead(y) == LOW)){} digitalWrite(LedGreen, LOW); } } }