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

screen = curses.initscr()

Initialize the curses library. screen will be the reference to the display to which I'm writing.

curses.noecho()

Do not echo characters to the screen as they are typed.

curses.cbreak()

Turn off input buffering and pass all character codes directly to the input function without processing.

screen.keypad ( 1 )

Convert escape sequences generated by some special keyboard keys to unique scan codes so that special keys can be handled as regular keystrokes.

screen.nodelay ( 1 )

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

 

Figure 7: A pie chart showing the distribution of pennies.

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.

The Author

Scott Sumner is the assistant manager of the Charlie Noble Planetarium at the Fort Worth Museum of Science and History. He enjoys using Python to solve as many problems as possible.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
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.

Learn More

News