ME 405: Mechatronics Portfolio
Vendotron.py File Reference

Created on Thu Jan 14 08:23:41 2021. More...

Functions

def Vendotron.on_keypress (thing)
 Callback which runs when the user presses a key.
 
def Vendotron.sumBalance (balance)
 Sums the current payment balance in dollars.
 
def Vendotron.getChange (price, payment)
 A function that calculates correct change for a given purchase. More...
 
def Vendotron.printWelcome (priceC, priceP, priceS, priceD)
 Startup welcome message. More...
 

Variables

 Vendotron.pushed_key = None
 Vendotron FSM. More...
 
int Vendotron.state = 0
 Initializes Vendotron FSM.
 
float Vendotron.priceC = 1.00
 Define price of Cuke.
 
float Vendotron.priceP = 1.10
 Define price of Popsi.
 
float Vendotron.priceS = 0.85
 Define price of Spryte.
 
float Vendotron.priceD = 0.95
 Define price of Dr. More...
 
 Vendotron.price = None
 Variable to temporarily hold the price of the selected drink.
 
list Vendotron.balance = [0,0,0,0,0,0,0,0]
 List containing quantities of each denomination that have been inserted by the user.
 
def Vendotron.change = getChange(0,balance)
 Returns the sum of the currrent balance in fewest possible denominations.
 

Detailed Description

Created on Thu Jan 14 08:23:41 2021.

Author
Miles Young
Date
01/14/2021

Vending machine FSM task
This vending machine finite state machine is capable of accepting payments in denominations from pennies to twenty dollar bills. It dispenses four different brands of soda. Prices and directions for paying and selecting a beverage are printed in the initial state of the task. In the next state payments are accepted and added to a running balance and a beverage selection can be made. If the balance is sufficient, a drink will be dispensed in the next state. If it is not, then a printed message will notify the user. In both cases, the FSM returns to the previous state and awaits another payment/drink selection. If the user requests the balance be returned, the FSM transitions to a final state in which this function is completed, after which the FSM returns to the initial state.

Function Documentation

◆ getChange()

def Vendotron.getChange (   price,
  payment 
)

A function that calculates correct change for a given purchase.

This function returns the change owed for a given purchase in the fewest denominations possible. The function accepts two the price of the purchase as a float, and the amount payed as a tuple holding the integer number of denominations.

Note
if the sum of the payment exceeds 10 trillion, resolution will decrease, beginning with rounding to nearest tenth of a cent followed by rounding to the nearest dollar at 10 quadrillion.
Parameters
priceA floating point value representing the price of the purchase in dollars and cents. If the resolution of the given price is greater than 1 cent, the price will be rounded to the nearest cent.
paymentA tuple holding the integer number of each denomination used in the payment, from pennies to twenty dollar bills.
Returns
If funds are sufficient, returns a tuple of change, if unsufficient or other typos detected, returns None.

◆ printWelcome()

def Vendotron.printWelcome (   priceC,
  priceP,
  priceS,
  priceD 
)

Startup welcome message.

This function is called in the initialization state of the Vendotron FSM. It displays the predefined prices for each beverage.

Parameters
priceCPrice of Cuke
pricePPrice of Popsi
priceSPrice of Spryte
priceDPrice of Dr. Pupper

Variable Documentation

◆ priceD

float Vendotron.priceD = 0.95

Define price of Dr.

Pupper

◆ pushed_key

Vendotron.pushed_key = None

Vendotron FSM.

Variable used to hold user keystroke