ME405: Mechatronics
Project Documentation and Portfolio by Neil Patel
vendo.py File Reference

This file contains a Finite State Machine representaion of a Vendotron vending machine. More...

Namespaces

 Lab0x01
 This package contains vendo.py.
 

Functions

def vendo.kb_cb (key)
 Callback function which is called when a key has been pressed. More...
 
def vendo.VendotronTask ()
 Runs one iteration of the task. More...
 

Variables

string vendo.last_key = ''
 The input key pressed by the user.
 
def vendo.vendo = VendotronTask()
 Initialize code to run FSM (not the init state). More...
 

Detailed Description

This file contains a Finite State Machine representaion of a Vendotron vending machine.

Function Documentation

◆ kb_cb()

def vendo.kb_cb (   key)

Callback function which is called when a key has been pressed.

Parameters
keyString representation of the key pressed by the user.
Returns
last_key String representation of the last key pressed by the user, stored as a global variable.

◆ VendotronTask()

def vendo.VendotronTask ( )

Runs one iteration of the task.

This program embodies the function of the vending machine designed in HW 0x00. Performs a particular state's operations in each iteration. On startup, display a message in the REPL (state 0). Moves into state 1 and stays there where the user can instruct the following actions -

1) Insert a coin by pressing one of the number keys (0-7) for their respective currencies. On doing so, the balance will be displayed in the REPL and the machine will go back to state 1. The number keys are '0' for a penny, '1' for a nickel, '2' for a dime, '3' for a quarter, '4' for $1, '5' for $5, '6' for $10, and '7' for $20.

2) Select a drink by pressing one of the drink keys. If the balance is insufficient, then an "Insufficient Funds" message will be displayed on the REPL along with the current balance and the price of the selected item and the machine will go back to state 1. If the current balance is sufficient, then the selcted item will be vended and the current balance computed. If there is no remaining balance left, then the machine will go back to state 1. However, if there is any remaining balance, then the user will be prompted to select another beverage. The drink keys are 'c' for Cuke, 'p' for Popsi, 's' for Spryte, 'd' for Dr. Pupper.

3) Eject at any time by pressing the 'e' key. On doing so, the full balance will be returned and the machine will go back to state 1.

If the machine is in state 1 for a long time, then it will go into an 'Idle' state in which a message will be displayed in the REPL saying 'Try Cuke today!'.

Returns
Does not return anything. Yields the state at the end so that the appropriate state is operated in the next iteration.

Variable Documentation

◆ vendo

def vendo.vendo = VendotronTask()

Initialize code to run FSM (not the init state).

This means building the iterator as generator object