A good cents exit survey
Ready to Go
Listing 9 is where the code actually begins execution. Line 1 initializes an instance of the display
class and passing in the address and baud rate of the serial port I want to open. This instance of the display
library now talks via /dev/ttyS0
. I could add a second display connected to a different serial port and initialize another instance of the class to run two displays independently if I desired.
Listing 9
Beginning Execution
On line 2, I create an instance of the menu
class and pass a reference to LCD
that I set up earlier. Line 3 then draws the initial LCD display.
Lines 5-9 set up the curses
library, which is designed to display text on character cell displays. I used it while developing the software before all of the hardware was ready for an embedded design. Even after the hardware was finished, I kept the curses display so I could plug a monitor into the Rasp Pi and see debug information. Table 1 describes the roles of the curses functions used here. On line 11, I initialize idleCount
to 0
to shut off the LCD backlight after a period of no activity.
Table 1
Curses Functions
Statement | Function |
---|---|
|
Initialize the curses library. |
|
Do not echo characters to the screen as they are typed. |
|
Turn off input buffering and pass all character codes directly to the input function without processing. |
|
Convert escape sequences generated by some special keyboard keys to unique scan codes so that special keys can be handled as regular keystrokes. |
|
Do not wait for input if none is available. |
The main loop of the program starts on line 13. On line 14, it checks to see whether the left interface button has been pressed and that it is not currently being ignored to wait for bounces to die down. If both conditions are OK, it turns on the LCD backlight, calls the LCDmenu.left
function, and sets LCDmenu.bounceCount [ 0 ]
to 50
. Lines 18-33 do the same thing for the other four buttons.
Note that I am calling the function with LCDmenu
instead of self
. Because I am calling the function from outside the class, I reference its functions via the instance – the variable I stored it in when I called the class name on line 2.
Line 34 is the catch-all for the string of if
/elif
statements that monitor the buttons. If no button has been pressed, I increment the idle counter. If it reaches 90,000, I reset it to 0
and turn off the LCD backlight.
Each button has its own while
loop on lines 40-44. The loop continues to run until its associated button is released, preventing a button press from being processed more than once.
Lines 46-47 decrement the bounceCount
counters if they are greater than 0
, and line 49 calls LCDmenu.countPennies()
to monitor the penny slots.
After the Show
After the pennies have been counted, you'll naturally want to see how well you performed. Once the usher has submitted the show's counts, it is available immediately on the planetarium's web dashboard.
The pennyGraph.php
module (Listing 10) generates a pie chart of the penny ratings (Figure 7). Line 1 tells Apache to let the PHP interpreter handle this block of code, and line 3 includes db.php
, which has connection information for the database server.
Listing 10
Pie Chart
Pennies in the Bank
Overall, the Penny Counter has performed well. Aside from the occasional penny getting jammed in the slot, it has successfully counted to the entire capacity of the theater (80 people).
One unanticipated outcome of the design that was discovered during beta testing was that children are more interested in putting their penny in a slot of their favorite color than they are in rating the show. We solved this problem by placing black covers on all of the funnels and fronting the counter with a sign to block the funnel colors. Reprinting all the funnels in the same color will eliminate this problem.
Infos
- Blender 3D Modeling and Creative Suite: https://www.blender.org
- PolyPrinter 3D printer: http://www.polyprinter.com
- Photomicrosensor: https://www.mouser.com/datasheet/2/307/en-ee_sx3096_w11_4096_w11-805875.pdf
- penny.py script: ftp://ftp.linux-magazine.com/pub/listings/linux-magazine.com/216/
« Previous 1 2 3 4
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.