{"id":14962012,"url":"https://github.com/madskjeldgaard/arduino-observer","last_synced_at":"2026-01-20T23:33:17.808Z","repository":{"id":252995352,"uuid":"842101101","full_name":"madskjeldgaard/arduino-observer","owner":"madskjeldgaard","description":"A simple library for working with the observer design pattern in Arduino","archived":false,"fork":false,"pushed_at":"2024-08-13T21:22:36.000Z","size":7,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T10:59:39.905Z","etag":null,"topics":["arduino","observer","platformio","raspberrypipico","teensy"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/madskjeldgaard.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},"funding":{"custom":["https://ko-fi.com/madskjeldgaard"]}},"created_at":"2024-08-13T17:12:22.000Z","updated_at":"2024-08-16T09:57:22.000Z","dependencies_parsed_at":"2024-08-13T22:10:27.533Z","dependency_job_id":null,"html_url":"https://github.com/madskjeldgaard/arduino-observer","commit_stats":null,"previous_names":["madskjeldgaard/arduino-observer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/madskjeldgaard/arduino-observer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madskjeldgaard%2Farduino-observer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madskjeldgaard%2Farduino-observer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madskjeldgaard%2Farduino-observer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madskjeldgaard%2Farduino-observer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/madskjeldgaard","download_url":"https://codeload.github.com/madskjeldgaard/arduino-observer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madskjeldgaard%2Farduino-observer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28618802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T22:24:05.405Z","status":"ssl_error","status_checked_at":"2026-01-20T22:20:31.342Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","observer","platformio","raspberrypipico","teensy"],"created_at":"2024-09-24T13:28:42.882Z","updated_at":"2026-01-20T23:33:17.792Z","avatar_url":"https://github.com/madskjeldgaard.png","language":"C++","funding_links":["https://ko-fi.com/madskjeldgaard"],"categories":[],"sub_categories":[],"readme":"# Arduino Observer \n\nThe [Observer Design Pattern](https://en.wikipedia.org/wiki/Observer_pattern) is a common design pattern used to define a subscription mechanism that notifies one or more objects of an event happening. \n\nIn the world of microcontrollers, this is particularly useful when reading potentiometers, encoders or buttons. Often you will want several things happening when a user touches the hardware interface, and with the observer design pattern, all these different things are seperated in a neat way that greatly simplifies the interface for the programmer and makes it easier to maintain because different concerns are seperatable in the code.\n\nFor example: A user presses a button and you want this event to trigger an LED on/off, post a message to the serial interface, trigger a MIDI Note, update some internal state, etc.\n\nThis library makes that easier by supplying a simple Observer and Observable class as well as a few optional helper classes for registering events when button presses happen or potentiometer values change. These include debouncing and value smoothing.\n\n# Features\n\n- Simple Observer and Observerable classes when you want to design your own event observers and observables.\n- Convenience classes for common interfaces:\n    - `ArduinoButton` / `ButtonObserver` – Set up a button with a de-noising debouncer and listen for event changes\n    - `ArduinoVoltage` / `VoltageObserver` – Set up an ADC input (like a potentiometer or an LDR), with smoothing including, and listen for event changes.\n\n## Usage\n\nSee [examples](examples) for more usage examples. \n\n```cpp\n/*\n *\n * This example shows how to register a button and two observers to it.\n *\n * The first observer posts the button state to the serial monitor.\n * The second observer blinks the built-in LED when the button is pressed.\n *\n */\n#include \"ArduinoButton.hpp\"\n#include \u003cArduino.h\u003e\n\n// Button pin\nconstexpr auto BUTTON_PIN = 2;\nconstexpr auto LED_PIN = LED_BUILTIN;\n\n// Debounce time\nconstexpr auto DEBOUNCE_TIME = 50;\n\n// Observable\nobs::ArduinoButton button(BUTTON_PIN, INPUT_PULLUP, DEBOUNCE_TIME);\n\n// An observer posting the button state to the serial monitor\nobs::ButtonObserver buttonPoster([](obs::ArduinoButton \u0026button,\n                                    const String \u0026field_name) {\n  Serial.println(\"Button event: \" + field_name);\n});\n\n// An observer blinking the built-in LED when the button is pressed\nobs::ButtonObserver buttonBlinker([](obs::ArduinoButton \u0026button,\n                                     const String \u0026field_name) {\n  if (field_name == \"fall\") {\n    digitalWrite(LED_BUILTIN, HIGH);\n  } else if (field_name == \"rise\") {\n    digitalWrite(LED_BUILTIN, LOW);\n  }\n});\n\nvoid setup() {\n  Serial.begin(115200);\n\n  pinMode(LED_PIN, OUTPUT);\n\n  button.subscribe(buttonPoster);\n  button.subscribe(buttonBlinker);\n\n  button.update();\n}\n\nvoid loop() { button.update(); }\n```\n\n### Platformio installation\n\nAdd the library to your lib_deps in `platformio.ini`\n\n```\nlib_deps = \n    https://github.com/madskjeldgaard/arduino-observer\n```\n\n### Dependencies\n\nThese dependencies are optional and only used if you use the `ArduinoButton` or `ArduinoVoltage` convenience classes.\n\nIf you install this library through platformio, they are automatically included.\n\n- [ResponsiveAnalogRead](https://github.com/dxinteractive/ResponsiveAnalogRead) – for ADC smoothing\n- [Debouncer](https://github.com/hideakitai/Debouncer) – for debouncing button presses\n\n### Making your own classes\n\nSee the [include/ArduinoButton.hpp](include/ArduinoButton.hpp) class file for inspiration on how to make your own.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadskjeldgaard%2Farduino-observer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadskjeldgaard%2Farduino-observer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadskjeldgaard%2Farduino-observer/lists"}