Main

This is the main function that coordinates all the modules to get the FLICKER to work at a high level

 

Main uses an internal state with the following states:

IDLE,

IR,

GRAPPLE,

DOWNLOAD,

FAIL,

SUCCESS,

RESET_SHOW 

 

main

      Initialize a 1[ms] clock for use by all modules

      Set I/O port pins to inputs or outputs

      Set Analog port pins to output or analog input

     

      Wait for 2 sec to give MP3 player time to boot up

 

      Initialize modules:

         Call initStepMotor() with an input of 100 steps

         Call initDownload()

         Call initLEDMap()

         Call initFlicker()

         Call initMusic()

     

      Set state to IDLE

 

      Loop Forever

         Execute code corresponding to current state

         Case IDLE:

            Turn off ultra-bright white LEDs using Flicker module

            Turn off red LEDs using Flicker module

            Turn off all stage indicator LEDs using Stage_LEDs module

 

            Check for active signal from forced start button or opto-iso using Flicker module

            If FlickerEvent is FLICKER_START

               Start LED guard map

               Check if IR beam is broken using IR module

               If IR beam is already broken

                  Set a flag indicating IR beam must read active before continuing to next stage

                  (this accounts for situation where player starts with hand already breaking IR

                   beam and forces the player to remove their hand and break the IR beam again in                       

                   order to progress to the next stage)

               Else

                  Set flag that IR beam read correctly on start up

               Set state to IR

        

         Case IR

            Start Mission Impossible music using Music module

            Turn off ultra-bright white LEDs using Flicker module

            Turn on red LEDs using Flicker module

            Turn on IR stage LED using Stage_LEDs module

 

            Check if guard has arrived using LEDMap module

            If LEDMapEvent is LEDMap_GUARD_ARRIVED

               Record the current time so that the fail “show” can be ended after a calibrated

               amount of time from now

               Set state to FAIL

 

            Check if IR beam is broken using IR module

            If IREvent is IR_BROKEN_STATUS

               If flag is set indicating that IR beam started already tripped

                  Do nothing

               Else

                  Set flag that the “hit floor” alarm is not tripped

                  Set state to GRAPPLE

            Else

               Reset flag (turn flag to zero) to indicate that the IR beam has read active and

               simply needs to be broken to move to next stage     

 

         Case GRAPPLE:

            If flag is set indicating “hit floor” alarm has been tripped

               Blink red LEDs with a frequency of 1/150[ms] using Flicker module

               Blink ultra-bright white LEDs with a frequency of 1/250[ms] using Flicker module

            Else

               Turn on ultra-bright white LEDs using Flicker module

               Turn off red LEDs using Flicker module

            Turn on GRAPPLE stage LED using Stage_LEDs module

 

            Check if guard has arrived using LEDMap module

            If LEDMapEvent is LEDMap_GUARD_ARRIVED

               Record the current time so that the fail “show” can be ended after a calibrated

               amount of time from now

               Set state to FAIL

        

            Allow user to move Tom with the grapple control dial and check Tom Cruise's position

            using the StepperMotor module

            If MotorStatus is MOTOR_NOT_IN_RANGE_STATUS
               Reset the download and turn off the progress LEDs using the Download module

            If MotorStatus is MOTOR_IN_RANGE_STATUS

               Check if the download has been started using Download module

               If DownloadEvent is DOWNLOAD_STARTED_EVENT

                  Turn off all progress LEDs using Download module

                  Set state to DOWNLOAD

            If MotorStatus is MOTOR_HIT_FLOOR_STATUS

               Speed up guard's progress on the floor by calling LEDMapGuardAlerted in the LEDMap

               module

               Set flag indicating “hit floor” alarm has been tripped

        

         Case DOWNLOAD:

            If flag is set indicating “hit floor” alarm has been tripped

               Blink red LEDs with a frequency of 1/150[ms] using Flicker module

               Blink ultra-bright white LEDs with a frequency of 1/250[ms] using Flicker module

            Else

               Turn on ultra-bright white LEDs using Flicker module

               Turn off red LEDs using Flicker module

            Turn on DOWNLOAD stage LED using Stage_LEDs module

        

            Check if guard has arrived using LEDMap module

            If LEDMapEvent is LEDMap_GUARD_ARRIVED

               Record the current time so that the fail “show” can be ended after a calibrated

               amount of time from now

               Set state to FAIL

 

            Check if download has completed and disk is in using Download module

            If DownloadEvent = DOWNLOAD_COMPLETE_EVENT AND the disk is not currently inserted

               Restart Mission Impossible theme using Music module

               Reset the download and turn off progress LEDs using Download module

               Record the current time so that the success “show” can be ended after a calibrated

               amount of time from now

               Set state to SUCCESS

 

         Case FAIL:

            Stop the music using the music module

            Blink the red LEDs at a frequency of 1/150[ms] using the Flicker module

            Turn off the ultra-bright LEDs using the Flicker module

            Get current time

            If current time minus start of FAIL time is greater than a calibrated time

               Signal next flicker to start using Flicker module

               Set state to RESET_SHOW

 

         Case SUCCESS:

            Blink ultra-bright white LEDs at a frequency of 1/150[ms] using Flicker module

            Turn off the red LEDs using Flicker module

            Slowly raise Tom Cruise back to start position with call to slowVictoryReset() in

            the StepperMotor module

            Get the current time

            If current time minus start of SUCCESS time is greater than a calibrated time

               Stop the music using the Music module

               Signal the next flicker to start using the Flicker module

               Set state to RESET_SHOW

 

         Case RESET_SHOW:

            Reset guard map using the LEDMap module

            Turn off all the stage indicator LEDs using the Stage_LEDs module

            Reset the download and turn off all progress LEDs using the Download module

            Turn off ultra-bright white LEDs using Flicker module

            Turn off red LEDs using Flicker module

            Turn off all stage indicator LEDs using Stage_LEDs module

            Check if Tom is back at the start position using the StepperMotor module

            While MotorStatus is MOTOR_RESETTING_STATUS

               Continue raising Tom Cruise

            Ram Tom into the stop for 50 steps to reset the stepper motor position using

            the StepperMotor module

            Set state to IDLE

 

Module Functions:

wait(wait_time)

  Wait until the current time minus the start time is greater than the wait time