Skip to main content

IO Emulator with LEDs and buttons

Project description

ioemu

screenshot

The ioemu-project provides an emulator for input/output operations with simple electronic components like LEDs and push buttons.

Installation and Upgrade

Use pip for a simple installation. For an update use install --upgrade.

  • Linux, MacOS: python3 -m pip install ioemu
  • Windows: python -m pip install ioemu

Starting the emulator

First start the emulator by entering ioemu on the commandline. A Gui will show up.

screenshot

It contains a slider for analog values between 0 and 99, threee LEDs and two push buttons from left to right.

LEDs

If the emulator is running, you can interact with it from any python program running on the same machine. First import the class Emulator from the ioemu package.

from ioemu import Emulator

Now create an instance of the emulator and switch some LEDs on. They can be controlled by setting the leds attribute.

emu = Emulator()
emu.leds = [True, False, True]

Buttons

screenshot

The emulator has two buttons. Their current state (pressed or not pressed) can be read from the attribute buttons. It's a bool array corresponding to the state of being pressed.

The following program lights up some LEDs depending on the button being pressed.

emu = Emulator()
while True:
    if emu.buttons[0]:
        emu.leds = [False, True, True]
        
    if emu.buttons[1]:
        emu.leds = [True, True, False]

    if not (emu.buttons[0] or emu.buttons[1]):
        emu.leds = [False, False, False]

Analog Value (0-99)

Let's look into a program that allows you to control the LEDs with the slider at the left. The current sliders value can be read from the analog_value attribute of the Emulator. Its value ranges from 0 to 99.

image

import time

emu = Emulator()
led_on = 0

while True:
    if 0 <= emu.analog_value < 25:
        emu.leds = [False, False, False]
    elif 25 <= emu.analog_value < 50:
        emu.leds = [True, False, False]
    elif 50 <= emu.analog_value < 75:
        emu.leds = [True, True, False]
    else:
        emu.leds = [True, True, True]

Demo

There is a demo program that can be started with python -m ioemu.demo. It will blink the LEDs and print the current button state as well as the analog value to console.

demo

You can find the source code in demo.py.

Bugs

If you find any bugs or have a feature request, feel free to file a ticket at the projects bugtracker on github.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ioemu-0.3.2.tar.gz (32.2 kB view details)

Uploaded Source

Built Distribution

ioemu-0.3.2-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file ioemu-0.3.2.tar.gz.

File metadata

  • Download URL: ioemu-0.3.2.tar.gz
  • Upload date:
  • Size: 32.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.7.0 Darwin/20.6.0

File hashes

Hashes for ioemu-0.3.2.tar.gz
Algorithm Hash digest
SHA256 cc5c25bbe2dd5992308406410d3ea50658467a1005c848e246e3c970b8221f00
MD5 eb1eaeb434620c1b91fc813c0b185635
BLAKE2b-256 e6c4759cec284beab0dce78b97256f58170c5a301fc68c1eb407994cbda09163

See more details on using hashes here.

File details

Details for the file ioemu-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: ioemu-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 30.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.7.0 Darwin/20.6.0

File hashes

Hashes for ioemu-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b03524540bc94ca70565f22009e0b46de7fe9ce358e9bc2e88e7aad8ca63d423
MD5 493df0b076affe6ad7b0be0d2877ac18
BLAKE2b-256 7ec1f30016f206777800ae43aa051debb509808848f6315642cf1ff9261332a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page