pyLegoMario


NamepyLegoMario JSON
Version 1.1 PyPI version JSON
download
home_pageNone
SummaryModule for handling connections with the Lego Mario toy
upload_time2024-10-30 12:34:29
maintainerNone
docs_urlNone
authorJamin Kauf, Bruno Hautzenberger
requires_python>=3.9
licenseNone
keywords lego python super mario lego mario bluetooth
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyLegoMario
```pip install pyLegoMario```

pyLegoMario is a script that connects to Lego Mario and reads its acceleromter,
tile sensor, and pants data.
To connect, you have to turn Mario on and then press the Bluetooth Button.
See mario_sample.py for a nice sample.
To disconnect you have to await Mario.disconnect() or await Mario.turn_off(),
as well as set Mario.autoReconnect = False


## TL;DR; "just show me how to use it!"
### The Basics
```python
from pyLegoMario import Mario, MarioWindow, run
# Initialize Mario
mario = Mario()
# Create GUI
MarioWindow(mario)
# call run() at the end of your program to keep the asyncio loop running
run()
```
### Use Mario in Your Own Programs With Callback Functions
```python
def my_pants_hook(mario: Mario, powerup: str) -> None:
    print(f"I'm wearing {powerup} pants!")

mario.add_pants_hook(my_pants_hook)
```
### Use Mario as a Controller in Pygame!
```python
import pygame
from pyLegoMario import PygameMario, AsyncClock
from pyLegoMario import ACC_EVENT, PANTS_EVENT, RGB_EVENT

pygame.init()
mario = PygameMario()
# use AsyncClock instead of pygame.time.Clock
clock = AsyncClock()
screen = pygame.display.set_mode(1200,600)
font = pygame.font.SysFont(None, 48)

while True:
    clock.tick()
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == RGB_EVENT:
            screen.fill((0,0,0))
            # write the current camera value onto the screen
            text = font.render(event.value, True, (255,255,255))
            screen.blit(text, (10,10))
# no need to call run() here, AsyncClock handles this
```
## You Can Do a Lot More!
Sample scripts can be found in the [Github Repository](https://github.com/Jackomatrus/pyLegoMario)

Tweet at me: [@Jackomatrus](https://www.twitter.com/Jackomatrus)

On Windows you will need Python 3.9 or higher for Bluetooth sockets to work properly.

I tested this on Mac and Windows. I have not tested this on Linux.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyLegoMario",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "lego, python, super mario, lego mario, bluetooth",
    "author": "Jamin Kauf, Bruno Hautzenberger",
    "author_email": "jamin.kauf@yahoo.de",
    "download_url": "https://files.pythonhosted.org/packages/b1/72/e5cb207e97b87ce4ebc3ef0430ff467fbab0279373a96b2cc2e8bdd8fe6d/pylegomario-1.1.tar.gz",
    "platform": null,
    "description": "# pyLegoMario\r\n```pip install pyLegoMario```\r\n\r\npyLegoMario is a script that connects to Lego Mario and reads its acceleromter,\r\ntile sensor, and pants data.\r\nTo connect, you have to turn Mario on and then press the Bluetooth Button.\r\nSee mario_sample.py for a nice sample.\r\nTo disconnect you have to await Mario.disconnect() or await Mario.turn_off(),\r\nas well as set Mario.autoReconnect = False\r\n\r\n\r\n## TL;DR; \"just show me how to use it!\"\r\n### The Basics\r\n```python\r\nfrom pyLegoMario import Mario, MarioWindow, run\r\n# Initialize Mario\r\nmario = Mario()\r\n# Create GUI\r\nMarioWindow(mario)\r\n# call run() at the end of your program to keep the asyncio loop running\r\nrun()\r\n```\r\n### Use Mario in Your Own Programs With Callback Functions\r\n```python\r\ndef my_pants_hook(mario: Mario, powerup: str) -> None:\r\n    print(f\"I'm wearing {powerup} pants!\")\r\n\r\nmario.add_pants_hook(my_pants_hook)\r\n```\r\n### Use Mario as a Controller in Pygame!\r\n```python\r\nimport pygame\r\nfrom pyLegoMario import PygameMario, AsyncClock\r\nfrom pyLegoMario import ACC_EVENT, PANTS_EVENT, RGB_EVENT\r\n\r\npygame.init()\r\nmario = PygameMario()\r\n# use AsyncClock instead of pygame.time.Clock\r\nclock = AsyncClock()\r\nscreen = pygame.display.set_mode(1200,600)\r\nfont = pygame.font.SysFont(None, 48)\r\n\r\nwhile True:\r\n    clock.tick()\r\n    pygame.display.update()\r\n    for event in pygame.event.get():\r\n        if event.type == RGB_EVENT:\r\n            screen.fill((0,0,0))\r\n            # write the current camera value onto the screen\r\n            text = font.render(event.value, True, (255,255,255))\r\n            screen.blit(text, (10,10))\r\n# no need to call run() here, AsyncClock handles this\r\n```\r\n## You Can Do a Lot More!\r\nSample scripts can be found in the [Github Repository](https://github.com/Jackomatrus/pyLegoMario)\r\n\r\nTweet at me: [@Jackomatrus](https://www.twitter.com/Jackomatrus)\r\n\r\nOn Windows you will need Python 3.9 or higher for Bluetooth sockets to work properly.\r\n\r\nI tested this on Mac and Windows. I have not tested this on Linux.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Module for handling connections with the Lego Mario toy",
    "version": "1.1",
    "project_urls": {
        "repository": "https://github.com/Jackomatrus/pyLegoMario"
    },
    "split_keywords": [
        "lego",
        " python",
        " super mario",
        " lego mario",
        " bluetooth"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "60ca895f677f379538be8790c83a85a0eb73f372d495990affe585d100b4178f",
                "md5": "b4bf0a9e7b7a36df9759296d17c3b2d0",
                "sha256": "1dce9dc1c2ceb62e2e3099afd5b7114438c0f5ba33328e6e5c503e55b87396fc"
            },
            "downloads": -1,
            "filename": "pyLegoMario-1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b4bf0a9e7b7a36df9759296d17c3b2d0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 110947,
            "upload_time": "2024-10-30T12:34:27",
            "upload_time_iso_8601": "2024-10-30T12:34:27.509920Z",
            "url": "https://files.pythonhosted.org/packages/60/ca/895f677f379538be8790c83a85a0eb73f372d495990affe585d100b4178f/pyLegoMario-1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b172e5cb207e97b87ce4ebc3ef0430ff467fbab0279373a96b2cc2e8bdd8fe6d",
                "md5": "4bf7dfe58a544a70581832d4c9ef03a1",
                "sha256": "578a56c3018f3784ae00882ad232d439d48db55ae4bf9a24c120e1aa7cca8745"
            },
            "downloads": -1,
            "filename": "pylegomario-1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "4bf7dfe58a544a70581832d4c9ef03a1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 112599,
            "upload_time": "2024-10-30T12:34:29",
            "upload_time_iso_8601": "2024-10-30T12:34:29.084499Z",
            "url": "https://files.pythonhosted.org/packages/b1/72/e5cb207e97b87ce4ebc3ef0430ff467fbab0279373a96b2cc2e8bdd8fe6d/pylegomario-1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-30 12:34:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Jackomatrus",
    "github_project": "pyLegoMario",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pylegomario"
}
        
Elapsed time: 0.48559s