Matthew's Portfolio
405_Lab0x01.py File Reference

This file runs the VendoTron FSM. More...

Functions

def 405_Lab0x01.kb_cb (key)
 Callback function inside keyboard module. More...
 
def 405_Lab0x01.getChange (price, balance)
 This file computes the change for a certain purchase. More...
 
def 405_Lab0x01.convertToCents (_moneyDict)
 Converts denominations and quantities to cents. More...
 
def 405_Lab0x01.vendoTronTask (debugFlag, payment)
 Generator used to hold the FSM for the vending machine. More...
 

Variables

int 405_Lab0x01.S0_INIT = 0
 The init state.
 
int 405_Lab0x01.S1_WAIT_FOR_ACTION = 1
 Waits for user to press a button.
 
int 405_Lab0x01.S2_DISPLAY_BALANCE = 2
 Display the current balance.
 
int 405_Lab0x01.S3_DO_TRANSACTION = 3
 Computations after a drink is selected.
 
int 405_Lab0x01.S4_QUERY_FOR_DRINK = 4
 Ask user for another drink.
 
int 405_Lab0x01.S5_RETURN_CHANGE = 5
 return change.
 
int 405_Lab0x01.S6_THANK_USER = 6
 Thank user for buying a drink.
 
int 405_Lab0x01.S7_TIME_OUT = 7
 System times out and reminds user to finish.
 
dictionary 405_Lab0x01.denomination
 Dictionary of denominations. More...
 
dictionary 405_Lab0x01.balance = {1:0, 5:0, 10:0, 25:0, 100:0, 500:0, 1000:0, 2000:0}
 A dictionary of the starting balance, which should be 0.
 
dictionary 405_Lab0x01.sodas = {'c':('Cuke',100), 'p':('Popsi',120), 's':('Spryte',85), 'd':('Dr. Pupper',110)}
 Dictionary for soda options. More...
 
dictionary 405_Lab0x01.change = {1:0, 5:0, 10:0, 25:0, 100:0, 500:0, 1000:0, 2000:0}
 A dictionary of the starting change, which should be 0.
 
list 405_Lab0x01.Keys = ["0","1","2","3","4","5","6","7","e","c","p","s","d","q","y","n"]
 A list of the possible keyboard commands that could be pressed.
 
 405_Lab0x01.last_key = None
 A variable to hold the last keystroke.
 
def 405_Lab0x01.vendo = vendoTronTask(False, balance)
 

Detailed Description

This file runs the VendoTron FSM.

The user will input the quantity of each denomination that they are using to purchase the item, along with the price of the item, and the required drink, and several operations will be utilitized to simulate the workings of an actual vending machine. See source code here: https://bitbucket.org/MatthewFrostCP/me405/src/master/Lab0x01/Lab0x01.py


Figure 1. FSM for VendoTron


Author
Matthew Frost
Date
Originally created on 04/08/21
Last modified on 04/08/21

Function Documentation

◆ convertToCents()

def 405_Lab0x01.convertToCents (   _moneyDict)

Converts denominations and quantities to cents.

When a dictionary of denominations and values are inputted, the corresponding value in cents is outputted.

◆ getChange()

def 405_Lab0x01.getChange (   price,
  balance 
)

This file computes the change for a certain purchase.

The user will input the quantity of each denomination that they are using to purchase the item, along with the price of the item, and the corresponding change will be calculated in terms of the quantity of each denomination that will be returned.

Parameters
priceThe price of the selected soda.
balanceA dictionary of the current balance.

◆ kb_cb()

def 405_Lab0x01.kb_cb (   key)

Callback function inside keyboard module.

When keyboard is pressed, it automatically gets sent to the callback function to assign a variable the letter pressed.

Parameters
keyThe key that was pressed to trigger the callback function.

◆ vendoTronTask()

def 405_Lab0x01.vendoTronTask (   debugFlag,
  payment 
)

Generator used to hold the FSM for the vending machine.

This implements the finite state machine used to simulate the vending machine. This will handle all the keyboard inputs, timing issues, and is in charge of calling other functions to calculate change and balance.

Parameters
debugFlagWhen enabled to True, more print commands are displayed.
paymentA dictionary with the current balance or payment.

Variable Documentation

◆ denomination

dictionary 405_Lab0x01.denomination
Initial value:
1= {'0':('Penny',1), '1':('Nickel',5), '2':('Dime',10),
2 '3':('Quarter',25), '4':('One',100), '5':('Five',500),
3 '6':('Ten',1000), '7':('Twenty',2000)}

Dictionary of denominations.

A dictionary of denominations that has the keyboard button as the key, and then a tuple for the name and amount of each denomination

◆ sodas

dictionary 405_Lab0x01.sodas = {'c':('Cuke',100), 'p':('Popsi',120), 's':('Spryte',85), 'd':('Dr. Pupper',110)}

Dictionary for soda options.

A dictionary of soda options that has the keyboard button as the key, and then a tuple for the name and price of each soda