Ryan McLaughlin | Mechatronics Portfolio
vendotron.py File Reference

Program for interactive virtual vending machine. More...

Functions

def vendotron.kb_cb (key)
 Callback method based on keyboard inputs. More...
 
def vendotron.getCents (moneyDict)
 Function for determining monetary value of a set of denominations. More...
 
def vendotron.getChange (price, payment, debugFlag)
 Function for determining least change for a set of denominations. More...
 
def vendotron.VendotronTask (debugFlag, idleTime)
 Generator function to run the main finite state machine. More...
 

Variables

def vendotron.vendo = VendotronTask(debugFlag = False, idleTime = 15 )
 Instance of generator/task. More...
 
list vendotron.callbackKeys = ['0','1','2','3','4','5','6','7','e','c','p','s','d','q']
 List containing all keys used as callbacks.
 
 vendotron.lastKey = None
 The last key released on the keyboard (must be a member of the list callbackKeys)
 

Detailed Description

Program for interactive virtual vending machine.

This file contains code for a virtual vending machine. Its general functionality includes the following:

  • Insertion and reading of various denominations (penny up to $20 bill) at any time
  • Selection of a drink at any time
  • Ejection of leftover change at any time
  • User-oriented messages such as prices, options, etc.
  • Function for determining least change for an input payment and price


See source code here: https://bitbucket.org/ryanmclaug/me_405/src/master/Lab0x01/vendotron.py

Author
Ryan McLaughlin
Date
Originally created on 04/08/21
Last modified on 04/13/21

Function Documentation

◆ getCents()

def vendotron.getCents (   moneyDict)

Function for determining monetary value of a set of denominations.

This function utilizes the .items() method for dictionary objects, to loop through pairs of denomination values and quantities.

Parameters
moneyDictis a dictionary containing the current set of denominations to be counted
Returns
cents is the value of all denominations in cents

◆ getChange()

def vendotron.getChange (   price,
  payment,
  debugFlag 
)

Function for determining least change for a set of denominations.

This function was first developed in HW0x01, and improved upon for use in the larger lab assigment of the vending machine. Given a set of denominations, the function must be able to determine the resulting change in the least number of denominations. If the payment is not sufficient, the function must recognize this and give a useful output.

Parameters
priceis the price in cents of the item to be purchased
paymentis a dictionary of denominations and their respective quantities
debugFlagis a input to the overall generator set to True when debugging code
Returns
change can be one of two things: if the payment exceeds or matches the price, change is a dictionary contatining the least change, and if the payment is not enough for the given price, change is set to None.

◆ kb_cb()

def vendotron.kb_cb (   key)

Callback method based on keyboard inputs.

In order to use the keyboard to set certain tasks into motion, a callback is used, along with the keyboard module for python.

Parameters
keyis the key released by the user

◆ VendotronTask()

def vendotron.VendotronTask (   debugFlag,
  idleTime 
)

Generator function to run the main finite state machine.

Each time the next() function is called for this function from within the "main script" of this file, the generator runs one iteration of the finite state machine, and yields the next state for the upcoming iteration.

Parameters
debugFlagis used to relay more information to the console while in the program development phase
idleTimeis the maximum allowable time without user action before a "scroll message" is displayed in the console
Returns
the varialbe state is yielded each time next() is called, and is the state corresponding to the starting point of the next iteration

Variable Documentation

◆ vendo

def vendotron.vendo = VendotronTask(debugFlag = False, idleTime = 15 )

Instance of generator/task.

Although this program does not utilize a class structure, it does use an object based structure. In this case, vendo is an instance of the function/generator VendtronTask which contains the main finite state machine for the file.