/* Moozy_firmware by Laurent CLAUDE 2023-09 Licence GPL v3 or later */ #include "USB.h" #include "USBHIDMouse.h" #include "USBHIDKeyboard.h" #include USBHIDMouse Mouse; USBHIDKeyboard Keyboard; Preferences moozyPrefs; // Variable and constant declarations // ---------------------------------- // set pin numbers for each inputs: const int PinInput1 = 1; const int PinInput2 = 2; const int PinInput3 = 3; #define LedMoozy 48 unsigned long debouncetime; bool keypressed = false, doNotRepeat = false; int cursorspeed, speed1, speed2, speed3; int currentspeed = 2; String todo, fctinput1, fctinput2, fctinput3; /* // Interrupt Service Routine // ------------------------- void ISR_Inputs () { if (!digitalRead(PinInput1)) { todo = fctinput1; } if (!digitalRead(PinInput2)) { todo = fctinput2; } if (!digitalRead(PinInput3)) { todo = fctinput3; } }*/ // Initialisations // --------------- void setup() { // initialize the buttons' inputs: pinMode(PinInput1, INPUT_PULLUP); pinMode(PinInput2, INPUT_PULLUP); pinMode(PinInput3, INPUT_PULLUP); pinMode(LedMoozy, OUTPUT); // retrieve settings from flash nvs moozyPrefs.begin("myapp", true); //namespace / true = RO MODE speed1 = moozyPrefs.getInt("speed1"); speed2 = moozyPrefs.getInt("speed2"); speed3 = moozyPrefs.getInt("speed3"); fctinput1 = moozyPrefs.getString("input1"); fctinput2 = moozyPrefs.getString("input2"); fctinput3 = moozyPrefs.getString("input3"); moozyPrefs.end(); cursorspeed = speed2 / 20; debouncetime = millis(); // initialize mouse control: Mouse.begin(); Keyboard.begin(); USB.begin(); // initialize interruptions /*attachInterrupt(digitalPinToInterrupt(PinInput1), ISR_Inputs, CHANGE); attachInterrupt(digitalPinToInterrupt(PinInput2), ISR_Inputs, CHANGE); attachInterrupt(digitalPinToInterrupt(PinInput3), ISR_Inputs, CHANGE);*/ // To say Hello on startup digitalWrite(LedMoozy, true); delay(150); digitalWrite(LedMoozy, false); delay(150); digitalWrite(LedMoozy, true); delay(150); digitalWrite(LedMoozy, false); } // Main loop // ------------- void loop() { if (!digitalRead(PinInput1)) { todo = fctinput1; } if (!digitalRead(PinInput2)) { todo = fctinput2; } if (!digitalRead(PinInput3)) { todo = fctinput3; } if ((todo != "") & (millis() > debouncetime + 100)) { if ((todo =="LC") & (!doNotRepeat)) {doNotRepeat = true; dolc(); } if ((todo =="LCD") & (!doNotRepeat)) {doNotRepeat = true; dolcd(); } if ((todo =="LCH") & (!doNotRepeat)) {doNotRepeat = true; dolch(); } if ((todo =="RC") & (!doNotRepeat)) {doNotRepeat = true; dorc(); } if ((todo =="RCD") & (!doNotRepeat)) {doNotRepeat = true; dorcd(); } if ((todo =="RCH") & (!doNotRepeat)) {doNotRepeat = true; dorch(); } if (todo =="up") { moveup(); } if (todo =="down") { movedown(); } if (todo =="right") { moveright(); } if (todo =="left") { moveleft(); } if (todo =="upright") { moveupright(); } if (todo =="upleft") { moveupleft(); } if (todo =="downright") { movedownright(); } if (todo =="downleft") { movedownleft(); } if (todo =="scrollup") { doscrollup(); } if (todo =="scrolldown") { doscrolldown(); } if ((todo =="speed1") & (!doNotRepeat)) {doNotRepeat = true; tospeed1(); } if ((todo =="speed2") & (!doNotRepeat)) {doNotRepeat = true; tospeed2(); } if ((todo =="speed3") & (!doNotRepeat)) {doNotRepeat = true; tospeed3(); } if (todo =="speedinc") { incspeed(); } if (todo =="speeddec") { decspeed(); } if ((todo =="mode1") & (!doNotRepeat)) {doNotRepeat = true; tomode1(); } if ((todo =="mode2") & (!doNotRepeat)) {doNotRepeat = true; tomode2(); } if ((todo =="mode3") & (!doNotRepeat)) {doNotRepeat = true; tomode3(); } debouncetime = millis(); } todo = ""; if ((digitalRead(PinInput1)) & (digitalRead(PinInput2)) & (digitalRead(PinInput3))) { doNotRepeat = false; } digitalWrite(LedMoozy, false); }