CALPOLY MECHATRONICS
Documentation for all Mechatronics Labs
vendotron.py File Reference

Documentation for vendotron.py. More...

Functions

def vendotron.getChange (self, price, payment)
 A function to calculate the change from a transaction. More...
 
def vendotron.VendotronTask ()
 A generator function that implements a finite state machine of the Vendotron vending machine. More...
 
def vendotron.kb_cb (key)
 Callback function which is called when a key has been pressed.
 

Variables

dictionary vendotron.stateMsgs
 A dictionary of descriptive messages for each state, used for debugging.1. More...
 
list vendotron.moneyKeys = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
 
string vendotron.last_key = ''
 The last key pressed on the keyboard.
 
dictionary vendotron.denomValues
 A dictionary of the cent values of each currency denomination. More...
 
int vendotron.paymentCents = 0
 the payment value in cents
 
dictionary vendotron.chng = {}
 A dictionary of change from the transaction.
 
int vendotron.centsLeft = paymentCents - price
 The cents remaining to be turned into change.
 
dictionary vendotron.v = denomValues[d]
 The cents value of the current denomination.
 
 vendotron.n = floor(centsLeft/v)
 The number of the current denomination needed for change.
 
def vendotron.vendo = VendotronTask()
 

Detailed Description

Documentation for vendotron.py.

This Python program simulates the opperation of a vending machine called the Vendotron.

The Vendotron sells four different types of drinks:

  • Cuke, $1.00
  • Popsi $1.20
  • Spryte $0.85
  • Dr. Pupper $1.10

To enter money into the machine the user can press numbers 0-9 on their keyboard, which correspond to increasing monetary denominations (1 = pennies, 2 = nickles, etc.). To select the drink they want the user can press 'c' for Cuke, 'p' for Popsi, 's' for Spryte, and 'd' for Dr. Pupper. To eject any remaining change the user can press 'e'.

Author
Eliot Briefer
Date
Apr. 22, 2020

Function Documentation

◆ getChange()

def vendotron.getChange (   self,
  price,
  payment 
)

A function to calculate the change from a transaction.

Parameters
priceAn integer representing the price in cents
paymentA dictionary of the payment bills {'pennies': 0, 'ones' : 0, ...}
Returns
A dictionary of the same form as payment with the change from the transaction returns None if payment is insufficient.

◆ VendotronTask()

def vendotron.VendotronTask ( )

A generator function that implements a finite state machine of the Vendotron vending machine.

The state machine for the Vendotron is shown below:

Variable Documentation

◆ denomValues

dictionary vendotron.denomValues
Initial value:
1 = {'hundereds' : 10000,
2  'fifties' : 5000,
3  'twenties' : 2000,
4  'tens' : 1000,
5  'fives' : 500,
6  'ones' : 100,
7  'quarters' : 25,
8  'dimes' : 10,
9  'nickles' : 5,
10  'pennies' : 1}

A dictionary of the cent values of each currency denomination.

◆ stateMsgs

dictionary vendotron.stateMsgs
Initial value:
1 = {0 : 's0 startup',
2  1 : 's1 idle',
3  2 : 's2 coin inserted',
4  3 : 's3 eject coins',
5  4 : 's4 vend cuke',
6  5 : 's5 vend popsi',
7  6 : 's6 vend spryte',
8  7 : 's7 vend dr. pupper',
9  8 : 's8 idle message',
10  9 : 's9 second beverage',
11  10 : 's10 insufficient funds'}

A dictionary of descriptive messages for each state, used for debugging.1.