Kyle Chuang | ME405 Mechatronics Portfolio
me405L1.py File Reference

Labx01: Vendotron Simulation. More...

Functions

def me405L1.on_keypress (thing)
 Callback which runs when the user presses a key.
 
def me405L1.getChange (price, payment)
 Computes change for monetary transaction. More...
 
def me405L1.printWelcome ()
 

Variables

int me405L1.state = 0
 Variable to indicate which state the system is in.
 
 me405L1.pushed_key = None
 
int me405L1.balance = 0
 
int me405L1.price = 0
 
int me405L1.display_balance = balance/100
 
int me405L1.display_price = 0
 

Detailed Description

Labx01: Vendotron Simulation.

I wrote this code to simulate the functionality of a fictional vending machine, the Vendotron. The code uses a finite state machine to display print statements which represent the actions of a real vending machine. On start up, the user is greeted with this message: Thirsty? Grab a cold drink today! ('c') Cuke | $2.00 ('p') Popsi | $4.25 ('s') Spryte | $3.75 ('d') Dr.Pupper | $6.25 The user can then enter "money" by pressing numbers on their keyboard: 0-Penny, 1-Nickel, 2-Dime, 3-Quarter, 4-One Dollar, 5-Five Dollars, 6-Ten Dollars, 7-Twenty Dollars. Each time a number is pressed, the remaining balance is updated.

At any time the user can press 'c', 'p','s', or 'd' to make a drink selection. The code then compares the drink price to the balance and determines if the purchase can be made. If so, "DRINK VENDED" will display, indicating that a drink was dispensed successfully. If not, then it will display "INSUFFICIENT FUNDS" with your remaining balance. Leftover balances can be "ejected" by pressing 'e' at any time during operation or additional selections can be made by inserting more money into the machine.

The program will run indefinitely so use 'ctrl + c' to exit whenever you are finished with the Vendotron.

Author
Kyle Chuang
Date
January 14, 2021

Function Documentation

◆ getChange()

def me405L1.getChange (   price,
  payment 
)

Computes change for monetary transaction.

This is my code that takes the expected price and payment amounts and returns a tuple with the change expected to be returned in the least denominations as possible. The return tuple is formatted as follows:

"(# of pennies, # of nickels, # of dimes, # of quarters, # of one dollar bills, # of five dollar bills, # of ten dollar bills, # of twenty dollar bills)"

Parameters
priceThe price of the item to be purchased
paymentThe payment balance used to purchase the item.
Returns
If funds are sufficient, returns a tuple of bills/coins. If insufficient, returns None.