[{"data":1,"prerenderedAt":62},["ShallowReactive",2],{"example-page-promicro-macropad":3},{"id":4,"info":5,"parts":6,"wired":13,"refs":14,"nets":15,"moreNets":56,"code":57},"promicro-macropad","The Pro Micro's ATmega32U4 has USB built in: the sketch makes it a keyboard and mouse for the PC (Keyboard.h, Mouse.h). Button SW1 on D2 types a greeting, SW2 on D3 sends Ctrl+C, SW3 on D4 Ctrl+V, SW4 on D5 moves the mouse in a square and clicks. Press the buttons while the simulation runs: the serial monitor shows what the PC receives (Keyboard \u002F Mouse) and, over the USB serial port, which button was pressed. The board is powered and connected over USB.",[7,10],[8,9],"button",4,[11,12],"pro_micro",1,false,{"A1":11,"SW1":8,"SW2":8,"SW3":8,"SW4":8},[16,31,38,44,50],{"name":17,"pins":18},"0",[19,22,25,27,29],[20,21],"A1","GND",[23,24],"SW1","2",[26,24],"SW2",[28,24],"SW3",[30,24],"SW4",{"name":32,"pins":33},"B1",[34,36],[20,35],"D2\u002FSDA",[23,37],"1",{"name":39,"pins":40},"B2",[41,43],[20,42],"~D3\u002FSCL",[26,37],{"name":45,"pins":46},"B3",[47,49],[20,48],"D4",[28,37],{"name":51,"pins":52},"B4",[53,55],[20,54],"~D5",[30,37],0,{"file":58,"lang":59,"text":60,"lines":61,"more":13},"sketch.ino","cpp","\u002F\u002F Pro Micro (ATmega32U4) as a macro keyboard: the board is a USB keyboard and mouse for the PC.\n\u002F\u002F  - button on D2: types a greeting\n\u002F\u002F  - button on D3: Ctrl+C, button on D4: Ctrl+V\n\u002F\u002F  - button on D5: moves the mouse in a small square and clicks\n\u002F\u002F The buttons switch to GND (internal pull-ups). The console shows what the PC receives\n\u002F\u002F (\"Keyboard ▸\" \u002F \"Mouse ▸\") and, over the USB serial port, which button was pressed.\n#include \u003CKeyboard.h>\n#include \u003CMouse.h>\n\nconst byte BUTTONS[4] = { 2, 3, 4, 5 };\nbool was[4];\nunsigned long lastChange[4];\n\nvoid setup() {\n  for (byte i = 0; i \u003C 4; i++) { pinMode(BUTTONS[i], INPUT_PULLUP); was[i] = HIGH; }\n  Keyboard.begin();\n  Mouse.begin();\n  Serial.begin(9600);\n}\n\nvoid shortcut(char key) {\n  Keyboard.press(KEY_LEFT_CTRL);\n  Keyboard.press(key);\n  delay(20);\n  Keyboard.releaseAll();\n}\n\nvoid square() {\n  const int dx[4] = { 40, 0, -40, 0 }, dy[4] = { 0, 40, 0, -40 };\n  for (byte side = 0; side \u003C 4; side++)\n    for (byte step = 0; step \u003C 4; step++) { Mouse.move(dx[side] \u002F 4, dy[side] \u002F 4); delay(10); }\n  Mouse.click();\n}\n\nvoid loop() {\n  for (byte i = 0; i \u003C 4; i++) {\n    bool now = digitalRead(BUTTONS[i]);\n    if (now != was[i] && millis() - lastChange[i] > 30) {      \u002F\u002F debounce\n      lastChange[i] = millis();\n      was[i] = now;\n      if (now == LOW) {                                        \u002F\u002F pressed\n        Serial.print(\"button on D\");\n        Serial.println(BUTTONS[i]);\n        if (i == 0) Keyboard.println(\"Hello from the Pro Micro!\");\n        if (i == 1) shortcut('c');\n        if (i == 2) shortcut('v');\n        if (i == 3) square();\n      }\n    }\n  }\n}",51,1796304409811]