{"id":15163030,"url":"https://github.com/oberoner21/simplekey","last_synced_at":"2026-01-29T21:03:29.292Z","repository":{"id":251335985,"uuid":"836603593","full_name":"Oberoner21/SimpleKey","owner":"Oberoner21","description":"Basic library debouncing keys and detect short and long pushes.","archived":false,"fork":false,"pushed_at":"2024-08-01T19:36:06.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T08:18:37.907Z","etag":null,"topics":["arduino","debouncing","esp2866","esp32"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Oberoner21.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-01T07:38:07.000Z","updated_at":"2024-08-04T11:04:03.000Z","dependencies_parsed_at":"2024-08-02T10:03:53.173Z","dependency_job_id":null,"html_url":"https://github.com/Oberoner21/SimpleKey","commit_stats":null,"previous_names":["oberoner21/simplekey"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oberoner21%2FSimpleKey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oberoner21%2FSimpleKey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oberoner21%2FSimpleKey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oberoner21%2FSimpleKey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Oberoner21","download_url":"https://codeload.github.com/Oberoner21/SimpleKey/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801170,"owners_count":20998339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","debouncing","esp2866","esp32"],"created_at":"2024-09-27T02:02:30.293Z","updated_at":"2026-01-29T21:03:24.243Z","avatar_url":"https://github.com/Oberoner21.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleKey\nSimple key is a basic library to debounce a key and handle short and long pushes. It can be used for all microcontrollers that use the Arduino framework. (Arduino, ESP2866, ESP32...)\nThe SimpleKey class was adapted and modificatet using the template of the library SimpleRotary from [mprogram](https://github.com/mprograms/SimpleRotary).\n\n-----\n## Arduino code\n### Getting started\nInclude the SimpleKey library and create a SimpleKey object specifying the pin number to which the key is connected.\n```\n#include \u003cSimpleKey.h\u003e\nconst uint8_t KEY_PIN = 41;\nSimpleKey key = SimpleKey(KEY_PIN);\n```\nBy default, the key is LOW activ and its connection pin on the microcontroller is set to INPUT_PULLUP mode. You can change this by specifying the third constructor parameter as followed.\nThe second parameter is then the debounce delay time in mS (by default 50mS).\n```\nSimpleKey key = SimpleKey(KEY_PIN, 50, LOW);\n```\n### Getting Key Push\nTo tell whether or not the button has been pressed simply call push();.\n```\nvoid loop()\n{\n    if(key.push() == 1)\n    {\n        Serial.print(\"Key pressed: \"); Serial.println(key.getKeyPin());\n    }\n}\n```\n### Getting Key Long Push\nIn most cases you will detect a short push and a long push in the same function. To do this, call getPushType(longPressTime). The parameter longPressTime defines the time period\nafter which pressing the button is considered a long push. If the button is released earlier, a short press is returned. Unlike the push() function, however, it is the time at which the button is released.\n```\nunsigned int longPressTime = 500;  // in mS\n\nvoid loop()\n{\n    switch(key.getPushType(longPressTime)\n    {\n        case 1:\n            Serial.print(\"Key short pressed: \"); Serial.println(key.getKeyPin());\n            break;\n        case 2:\n            Serial.print(\"Key long pressed: \"); Serial.println(key.getKeyPin());\n            break;\n    }\n}\n```\n### Handle Key Fields\nTo handle multiple keys, create a separate SmartKey object for each key. It is best to first define the pin numbers of the individual keys in an array. A second array stores the pointers to the corresponding SmartKey objects.\n```\n// Keys pin defenition\nconst uint8_t KEY_LEFT = 42;\nconst uint8_t KEY_UP = 40;\nconst uint8_t KEY_DOWN = 41;\nconst uint8_t KEY_RIGHT = 39;\nconst uint8_t KEY_A = 38;\nconst uint8_t KEY_B = 45;\n\nconst uint8_t KEYS_COUNT = 6;   // counter of keys\nconst uint8_t KEYS_PINS[6] = { KEY_LEFT, KEY_UP, KEY_DOWN, KEY_RIGHT, KEY_A, KEY_B }; // array of key pins\nSimpleKey *Keys[KEYS_COUNT] = {0};  // initialize a array of pointer to the SimpleKey objects for any key\n```\nIn the setup() methode you create and save the SmartKey objects for all the keys.\n```\nvoid setup(void) \n{\n    Serial.begin(115200);\n\n    // Creates Simple Key Object for any key and store the pointer to the objects into Keys array\n    for(byte i=0; i\u003cKEYS_COUNT; i++)\n    {\n      Keys[i] = new SimpleKey(KEYS_PINS[i]);\n    }\n}\n```\nThen you loop over the keys pointer array and detect key pushes.\n```\nvoid loop() \n{\n  // loop over the keys array\n  for( auto \u0026key : Keys )\n  {\n    // if current key pressed?\n    if(key-\u003epush() == 1)\n    {\n        Serial.print(\"Key short pressed: \"); Serial.println(key-\u003egetKeyPin());\n    }\n  }\n}\n```\nFor more and detailed informations, visit the example section.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foberoner21%2Fsimplekey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foberoner21%2Fsimplekey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foberoner21%2Fsimplekey/lists"}