Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
displayotron [2016/06/28 11:28] – created peltzer | displayotron [2023/07/03 10:15] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | === Bild === | ||
+ | {{displayotron.jpg? | ||
+ | |||
+ | === Was ist es? === | ||
+ | |||
+ | Das Displayotron 3000 ist (dot3k) ist ein Bauteil bestehend aus einem LCD-Display mit einer 9-Segment Anzeige und LED-Backlight. Außerdem ist ein 4-Richtungs Joystick angebracht, der neben der 4 Richtungen auch eine Button-Funktion besitzt. In folgenden Beispielen wird zunächst gezeigt, wie man Text auf dem LCD ausgibt, während das ungleich komplexere, zweite Beispiel ein Menü erzeugt, das mit dem Joystick bedient werden kann. | ||
+ | |||
+ | === CODE 1 === | ||
+ | |||
+ | <file python dot3k_basic.py> | ||
+ | |||
+ | import dot3k.lcd as lcd | ||
+ | |||
+ | # Den Screen leeren und Text auf dem Bilschirm ausgeben | ||
+ | lcd.clear() | ||
+ | lcd.write(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | === CODE 2 === | ||
+ | |||
+ | <file python dot3k.py> | ||
+ | |||
+ | # | ||
+ | |||
+ | import sys | ||
+ | |||
+ | sys.path.append(' | ||
+ | |||
+ | #restlicher Import von Bibliotheken für diverse Funktionen des DOT3K | ||
+ | import dot3k.joystick as joystick | ||
+ | import dot3k.lcd as lcd | ||
+ | import dot3k.backlight | ||
+ | from dot3k.menu import Menu, MenuOption | ||
+ | import time | ||
+ | import os | ||
+ | import threading, subprocess | ||
+ | |||
+ | |||
+ | class Beispielmenue(MenuOption): | ||
+ | |||
+ | |||
+ | def __init__(self): | ||
+ | self.selected_option = 0 | ||
+ | |||
+ | self.options = [ | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ] | ||
+ | |||
+ | |||
+ | self.actions = [ #Den jeweiligen Menuepunkten Actions zuweisen | ||
+ | self.handle_Option1, | ||
+ | self.handle_Option2, | ||
+ | self.handle_Option3, | ||
+ | self.handle_exit | ||
+ | ] | ||
+ | |||
+ | MenuOption.__init__(self) | ||
+ | #hier folgen die Definitionen der Menuepunkte, | ||
+ | def handle_exit(self): | ||
+ | lcd.clear | ||
+ | os._exit(1) | ||
+ | |||
+ | def handle_Option1(self): | ||
+ | print" | ||
+ | |||
+ | def handle_Option2(self): | ||
+ | print" | ||
+ | |||
+ | def handle_Option3(self): | ||
+ | print" | ||
+ | |||
+ | # | ||
+ | |||
+ | def select_option(self): | ||
+ | self.actions[ self.selected_option ]() | ||
+ | |||
+ | def next_option(self): | ||
+ | self.selected_option = (self.selected_option + 1) % len(self.options) | ||
+ | |||
+ | def prev_option(self): | ||
+ | self.selected_option = (self.selected_option - 1) % len(self.options) | ||
+ | |||
+ | def up(self): | ||
+ | self.prev_option() | ||
+ | |||
+ | def down(self): | ||
+ | self.next_option() | ||
+ | |||
+ | def right(self): | ||
+ | self.select_option() | ||
+ | |||
+ | def get_current_option(self): | ||
+ | return self.options[ self.selected_option ] | ||
+ | |||
+ | def get_next_option(self): | ||
+ | return self.options[ (self.selected_option + 1) % len(self.options) ] | ||
+ | |||
+ | def get_prev_option(self): | ||
+ | return self.options[ (self.selected_option - 1) % len(self.options) ] | ||
+ | |||
+ | def redraw(self, | ||
+ | | ||
+ | menu.write_option( | ||
+ | row=0, | ||
+ | margin=1, | ||
+ | icon='', | ||
+ | text=self.get_prev_option() | ||
+ | ) | ||
+ | | ||
+ | menu.write_option( | ||
+ | row=1, | ||
+ | margin=1, | ||
+ | icon='>', | ||
+ | text=self.get_current_option() | ||
+ | ) | ||
+ | | ||
+ | menu.write_option( | ||
+ | row=2, | ||
+ | margin=1, | ||
+ | icon='', | ||
+ | text=self.get_next_option() | ||
+ | ) | ||
+ | # | ||
+ | |||
+ | dot3k.backlight.rgb(255, | ||
+ | |||
+ | menu = Menu( | ||
+ | structure={ | ||
+ | ' | ||
+ | }, | ||
+ | lcd=dot3k.lcd | ||
+ | ) | ||
+ | |||
+ | #Virtuell den " | ||
+ | |||
+ | menu.right() | ||
+ | |||
+ | #Festlegen, was die Joysticktasten bewirken: | ||
+ | |||
+ | @dot3k.joystick.on(dot3k.joystick.UP) | ||
+ | def handle_up(pin): | ||
+ | menu.up() | ||
+ | |||
+ | @dot3k.joystick.on(dot3k.joystick.DOWN) | ||
+ | def handle_down(pin): | ||
+ | menu.down() | ||
+ | |||
+ | @dot3k.joystick.on(dot3k.joystick.RIGHT) | ||
+ | def handle_right(pin): | ||
+ | menu.right() | ||
+ | |||
+ | # | ||
+ | |||
+ | while 1: | ||
+ | menu.redraw() | ||
+ | time.sleep(0.01) | ||
+ | </ |