{"id":24495565,"url":"https://github.com/nitz/cie1931","last_synced_at":"2026-03-13T00:31:44.312Z","repository":{"id":77114524,"uuid":"282027622","full_name":"nitz/Cie1931","owner":"nitz","description":"Cie1931 based PWM DC Generator for linear LED brightness ramps","archived":false,"fork":false,"pushed_at":"2023-06-07T19:26:33.000Z","size":64,"stargazers_count":14,"open_issues_count":3,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-03T01:43:20.293Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nitz.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":{"github":"nitz","ko_fi":"cmd","custom":["https://cmd.wtf/crypto"]}},"created_at":"2020-07-23T18:32:24.000Z","updated_at":"2025-04-19T13:26:41.000Z","dependencies_parsed_at":"2025-01-21T20:40:03.690Z","dependency_job_id":null,"html_url":"https://github.com/nitz/Cie1931","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nitz/Cie1931","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitz%2FCie1931","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitz%2FCie1931/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitz%2FCie1931/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitz%2FCie1931/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nitz","download_url":"https://codeload.github.com/nitz/Cie1931/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitz%2FCie1931/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30451542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T21:31:01.033Z","status":"ssl_error","status_checked_at":"2026-03-12T21:30:43.161Z","response_time":114,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":[],"created_at":"2025-01-21T20:27:55.647Z","updated_at":"2026-03-13T00:31:44.294Z","avatar_url":"https://github.com/nitz.png","language":"C++","funding_links":["https://github.com/sponsors/nitz","https://ko-fi.com/cmd","https://cmd.wtf/crypto"],"categories":[],"sub_categories":[],"readme":"[![arduino-library-badge](https://www.ardu-badge.com/badge/CIE1931.svg?)](https://www.ardu-badge.com/CIE1931)\n\n# CIE1931 LED Linear Brightness Ramp\n\nDoes your LED brightness ramp like this as you increase your PWM duty cycle?\n\n![sad led noises](https://github.com/nitz/Cie1931/blob/main/images/leds_uncorrected.png?raw=true)\n\nBut you'd rather them ramp up like this, smooth and pleasing to the eye?\n\n![giggles in diode emmited light](https://github.com/nitz/Cie1931/blob/main/images/leds_corrected.png?raw=true)\n\nThen do I have the tiny library for you!\n\n## Description\n\nCie1931 is a small C++ library (if you can call it that!) that uses constexpr to generate a lookup table for translating a PWM duty cycle scale into a mostly linear brightness output.\n\n## Usage\n\nThis code should run on basically any platform with a C++11 complier for it. You shouldn't even need floating point support on your target platform, because the math is all done at compile time.\n\nUsing it is easy. Declare the curve with the settings you want, and use it like a lookup table. Here's an Arduino example:\n\n```cpp\n\n#include \"cie1931.hpp\"\n\nconstexpr Cie1931\u003c\u003e cie1931;\n\n// Optionally you may specify via template pameters:\n//  - the max duty cycle value of your PWM (InputMax)\n//  - the max resultant duty cycle value (OutputMax)\n//  - the lookup table variable type (ResultType)\n// e.g.: Cie1931\u003c512, 1023, uint16_t\u003e curve;\n// Would specify a curve with 512 input values\n// that produces a range from 0-1023, stored\n// in 16 bit unsigned integers.\n\nsize_t pwmStep = 0;\nconstexpr int PWM_PIN = 9;\n\nvoid setup()\n{\n\t// no need to do any setup, the curve is already ready!\n}\n\nvoid loop()\n{\n\t// restart our step if we go past the length\n\tif (pwmStep \u003e= cie1931.Length)\n\t{\n\t\tpwmStep = 0;\n\t}\n\t\n\t// step through each value in the generated curve\n\tuint8_t pwmVal = cie1931[pwmStep++];\n\n\t// set our PWM DC\n\tanalogWrite(PWM_PIN, pwmVal);\n\t\n\t// a short pause before moving to the next value\n\tdelay(50);\n}\n```\n\n## Acknowledgments \u0026 Licenses\n\nThis project is MIT licensed. See `LICENSE` for more information.\n\nSpecial thanks to [Jared Sanson](https://github.com/jorticus)'s [blog post](https://jared.geek.nz/2013/feb/linear-led-pwm) that led (pun intended) to me creating this small tool. I found their approach to the generation of a lightness curve novel, and wanted to be able to do it at compile time without needing to create source files should I change my settings. Images are also via Jared.\n\nPlease feel free to open an issue or PR if you find a bug or have a suggestion!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitz%2Fcie1931","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnitz%2Fcie1931","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitz%2Fcie1931/lists"}