State Diagrams / Pseudocode
Below, the State Diagrams for our system's main State Machines are shown, with corresponding pseudocode shown as well.
SYSTEM STATE MACHINE
The System State machine controls the high level activity of the game console -- controlling overall game time, score (crops killed), and health. It also initializes and resets all other State Machines by sending the appropriate events.
System State Machine Pseudocode
|
|
CROP STATE MACHINE
Crop State Machine -- there were four identical machines running in parallel, each representing one of the four crops that a user could interact with during gameplay. The critical distinction between each crop SM is the hardware ports / register addresses to which each corresponding servo / phototransistor / etc. is uniquely mapped.
Crop State Machine Pseudocode
|
|
WATER STATE MACHINE
The Water State Machine controls the Watering aspects of our game system, including the Water Level, Water Release Valve, Pump Crank, and Watering Hose user interactions.
Water State Machine Pseudocode
|
|
TIMERS
Below, a list and brief description of the 16 timers used for the project are shown:
TIMER00: CROP_A_DEHYDRATION_TIMER -- timer for dehydrating crop
TIMER01: CROP_A_FLASHING_TIMER -- timer for flashing LEDs
TIMER02: CROP_A_UTILITY_TIMER -- timer for utility {debouncing, overwatered} event
TIMER03: CROP_B_DEHYDRATION_TIMER -- timer for dehydrating crop
TIMER04: CROP_B_FLASHING_TIMER -- timer for flashing LEDs
TIMER05: CROP_B_UTILITY_TIMER -- timer for utility {debouncing, overwatered} event
TIMER06: CROP_C_DEHYDRATION_TIMER -- timer for dehydrating crop
TIMER07: CROP_C_FLASHING_TIMER -- timer for flashing LEDs
TIMER08: CROP_C_UTILITY_TIMER -- timer for utility {debouncing, overwatered} event
TIMER09: CROP_D_DEHYDRATION_TIMER -- timer for dehydrating crop
TIMER10: CROP_D_FLASHING_TIMER -- timer for flashing LEDs
TIMER11: CROP_D_UTILITY_TIMER -- timer for utility {debouncing, overwatered} event
TIMER12: SYSTEM_GAME_TIMER -- timer for keeping track of overall gameplay time
TIMER13: SYSTEM_UTILITY_TIMER -- timer for utility {debouncing, flashing upon game over / standby} event
TIMER14: WATERING_BUTTON_DEBOUNCING_TIMER -- timer for debouncing water button
TIMER15: CROP_WATERING_TIMER -- timer for watering crops quasi continuously
TIMER00: CROP_A_DEHYDRATION_TIMER -- timer for dehydrating crop
TIMER01: CROP_A_FLASHING_TIMER -- timer for flashing LEDs
TIMER02: CROP_A_UTILITY_TIMER -- timer for utility {debouncing, overwatered} event
TIMER03: CROP_B_DEHYDRATION_TIMER -- timer for dehydrating crop
TIMER04: CROP_B_FLASHING_TIMER -- timer for flashing LEDs
TIMER05: CROP_B_UTILITY_TIMER -- timer for utility {debouncing, overwatered} event
TIMER06: CROP_C_DEHYDRATION_TIMER -- timer for dehydrating crop
TIMER07: CROP_C_FLASHING_TIMER -- timer for flashing LEDs
TIMER08: CROP_C_UTILITY_TIMER -- timer for utility {debouncing, overwatered} event
TIMER09: CROP_D_DEHYDRATION_TIMER -- timer for dehydrating crop
TIMER10: CROP_D_FLASHING_TIMER -- timer for flashing LEDs
TIMER11: CROP_D_UTILITY_TIMER -- timer for utility {debouncing, overwatered} event
TIMER12: SYSTEM_GAME_TIMER -- timer for keeping track of overall gameplay time
TIMER13: SYSTEM_UTILITY_TIMER -- timer for utility {debouncing, flashing upon game over / standby} event
TIMER14: WATERING_BUTTON_DEBOUNCING_TIMER -- timer for debouncing water button
TIMER15: CROP_WATERING_TIMER -- timer for watering crops quasi continuously
ADDITIONAL SOURCE FILES
In addition to the main three state machines, additional supporting source files were used, including helper (utility) function and hardware-specific modules, as well as relevant files that leverages Ed Carryer's ES_Framework system. The supporting source / header files are shown and described below:
CropFunctions: A helper file used by all Crop State Machines. It includes utility functions that initialize and control specific crop servos / LEDs / Phototransistor pins.
|
|
|
KeyParser: A debugging module that allows full control of gameplay and internal / external events via specific key presses
|
|
|
ShiftRegisterWrite: A hardware-interfacing module that initializes and controls data being sent to the Shift Register
|
|
|
Framework Modules: main.c controls the initial one-time hardware initialization necessary, ES_Configure.h controls assignment and organization of active SMs and events
|
|
|