{"id":26871136,"url":"https://github.com/codeadamca/spike-distance","last_synced_at":"2025-10-25T18:38:11.229Z","repository":{"id":115328595,"uuid":"514747147","full_name":"codeadamca/spike-distance","owner":"codeadamca","description":"About A basic example of using MicroPython and the distance sensor with the LEGO Spike hub.","archived":false,"fork":false,"pushed_at":"2025-01-26T22:25:47.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T07:18:31.707Z","etag":null,"topics":["lego","mindstorms","python","spike"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeadamca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-07-17T04:36:14.000Z","updated_at":"2025-01-26T22:25:51.000Z","dependencies_parsed_at":"2025-01-26T23:30:01.469Z","dependency_job_id":null,"html_url":"https://github.com/codeadamca/spike-distance","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codeadamca/spike-distance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fspike-distance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fspike-distance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fspike-distance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fspike-distance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeadamca","download_url":"https://codeload.github.com/codeadamca/spike-distance/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fspike-distance/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281003219,"owners_count":26428017,"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","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["lego","mindstorms","python","spike"],"created_at":"2025-03-31T07:18:33.873Z","updated_at":"2025-10-25T18:38:11.195Z","avatar_url":"https://github.com/codeadamca.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# LEGO® Spike Hub and the Distance Sensor\n\nA Python snippet utilizing the LEGO Spike distance sensor, [MicroPython](https://lego.github.io/MINDSTORMS-Robot-Inventor-hub-API/), and the `get_distance_cm()` and `light_up()` commands.\n\n## Sample Code\n\n```py\nfrom mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App\nfrom mindstorms.control import wait_for_seconds, wait_until, Timer\nfrom mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to\nimport math\n\nhub = MSHub()\n\ndistance_sensor = DistanceSensor('A')\n\npixels = '00000:00000:00000:00000:00000'\n\nwhile True:\n\n    dist_cm = distance_sensor.get_distance_cm()\n    dist_inches = distance_sensor.get_distance_inches()\n\n    if equal_to(dist_cm, None):\n        pass\n\n    elif less_than(dist_cm, 5):\n        pixels = '99999:99999:99999:99999:99999'\n\n    elif less_than(dist_cm, 10):\n        pixels = '88888:88888:88888:88888:88888'\n\n    elif less_than(dist_cm, 15):\n        pixels = '77777:77777:77777:77777:77777'\n\n    elif less_than(dist_cm, 20):\n        pixels = '66666:66666:66666:66666:66666'\n\n    elif less_than(dist_cm, 25):\n        pixels = '55555:55555:55555:55555:55555'\n\n    elif less_than(dist_cm, 30):\n        pixels = '44444:44444:44444:44444:44444'\n\n    elif less_than(dist_cm, 35):\n        pixels = '33333:33333:33333:33333:33333'\n\n    elif less_than(dist_cm, 40):\n        pixels = '22222:22222:22222:22222:22222'\n\n    elif less_than(dist_cm, 45):\n        pixels = '11111:11111:11111:11111:11111'\n\n    else:\n        pixels = '00000:00000:00000:00000:00000'\n        \n    hub.light_matrix.show(pixels)\n    print(dist_cm)\n\n    if hub.left_button.is_pressed() and hub.right_button.is_pressed():\n\n        break\n\nhub.speaker.beep()\n```\n\n***\n\n## Repo Resources\n\n* [Visual Studio Code](https://code.visualstudio.com/)\n* [MicroPython for LEGO Robot Inventor](https://www.lego.com/en-ca/themes/mindstorms/downloads)\n* [LEGO Mindstorms](https://www.lego.com/en-ca/themes/mindstorms)\n* [LEGO Mindstorms App for Mac](https://apps.apple.com/us/app/lego-mindstorms-inventor/id1515448947)\n* [LEGO Mindstorms App for Android](https://play.google.com/store/apps/details?id=com.lego.retail.mindstorms)\n* [LEGO Mindstorms App for Windows](https://www.microsoft.com/store/apps/9N7GN3KC2GK6)\n\n\u003cbr\u003e\n\u003ca href=\"https://codeadam.ca\"\u003e\n\u003cimg src=\"https://cdn.codeadam.ca/images@1.0.0/codeadam-logo-coloured-horizontal.png\" width=\"200\"\u003e\n\u003c/a\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fspike-distance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeadamca%2Fspike-distance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fspike-distance/lists"}