Introduction
Welcome to Week 5 of the I Ching hexagrams project. At a last I have the code stable enough to create a video to show what i have achieved. It might not look that impressive, but I have managed to get (most of) the bugs out of the start-up code so that the display output is reasonably predictable.
What I Have Done So Far
The code that underlies this little video consists of the following elements:
- Introductory Splash screen based on the sysinfo.py module from the PiFaceCAD library, but adapted to include alternation between a fixed text instruction page and an animated depiction of the I Ching characters. They should be displayed vertically as in the graphic above to represent the way the Chinese would write them, but the PiFaceCAD display needs to be horizontally aligned for the Western characters to display correctly
- Menu choices based on the radio.py module in the PiFaceCAD library, but adapted to deal with multiple menu levels.
- Background program modules to handle the routine tasks.
- Interrupt handlers to process the switch presses
- creation of a global 'menus' class to manage passing of control tokens between the background code and the interrupt handlers and to control the transition between menus by passing pointer values.
Implementation of exception handlers to trap unexpected events.
The code is probably not very elegant, but it represents how far I have come in learning Python.
What the Video Shows
The video starts with the instruction screen, and then alternates this with a depiction of the I Ching characters that moves right and left in the display. The right hand (slightly separated) button is designated the 'Back' button, and pressing this from the splash screen invokes the first page of the top-level menu. Pressing any of the other buttons will jump to a specific page in the top-level menu, but i could only show one exit from the splash screen.
Once in the main part of the program, pressing either of the four closely-spaced buttons will select a specific menu page. I did not demonstrate it in the video, but moving the 'T' button left and right will move through the menu options, rolling around through the ends, to allow menus of more than four options to be accommodated.
Pressing the 'T' button in will invoke an action associated with the menu choice: this can currently be one of:
- Select a lower level menu.
- Invoke a command, such as calling a function or other module
- Quit the program.
In the video, the beginning text of the 'Cast Hexagram' level 2 menu (Stalks) can be seen before a bug causes it to be overwritten with the error message from the exception handler.
I inadvertently pressed the 'back' button twice when returning to the top-level menu: 'Cast Hexagram' can be seen briefly before the 'Halt Requested' message identifies that the back button was pressed from the top-level menu.
Control is then passed back to the background program, which stops after displaying the 'Program Stopped' message.
Further bugs mean that the event listeners for the switches are not switched off, and some interesting things then happen to the display.

Top Comments