IO Emulator with LEDs and buttons
Project description
ioemu
The ioemu-project provides a simple emulator for input/output operations with simple electronic components like LEDs and push buttons.
Installation
Use pip for a simple installation
- 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.
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 interact with it from any python program. 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
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.
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)
Next a program that lets you control the LEDs with the slider at the left. The current sliders value can be read from the analog_value
attribute. Its value ranges from 0 to 99.
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]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.