Name:
#ifdef simulating
Syntax:

#IFDEF SIMULATING
   (code)
#ENDIF

#IFDEF SIMULATING
   (code)
#ELSE
   (code)
#ENDIF

#IFNDEF SIMULATING
   (code)
#ENDIF

#IFNDEF SIMULATING
   (code)
#ELSE
   (code)
#ENDIF

Description:

The 'simulating' label will automatically be defined whenever a program is being simulated in PICAXE Editor 6. It will not be defined when the program code has been downloaded into a physical PICAXE device. This allows code to be conditionally included when the program is being simulated (#ifdef) or executed in the physical PICAXE device (#ifndef).

This is useful for adding code which helps during simulation when debugging and testing program code. It can be particularly useful when a specific value is desired from an input to be able to test the operation of the code for that specific value. For example, the following code will force the 'b0' temperature value to always be 20C when simulated, regardless of what value was placed into 'b0' by the 'readtemp' command -

  readtemp C.0, b0
  #ifdef simulating
    b0 = 20
  #endif

It is also useful for excluding code which is not required during simulation. For example, a PICAXE program may need to delay 15 seconds when it starts to allow connected hardware to be ready for use. It is not desirable to have to wait 15 seconds every time the program is simulated. By using '#ifndef simulating' code can be specified which will only be executed when not simulating -

  #ifndef simulating
    pause 15000
  #endif

Applies To:
All
See Also:
Related Create:
    Share:
    Print:

    Including code when simulating

    This code will calculate the nearest (rounded) Fahrenheit temperature from a DS18B20 Celsius temperature reading . When simulating we will force the temperature reading to appear as if it was 20C in order to check that the result is correct and the calculation performs as expected; 20C=68F.

    Code Example:
    main:	readtemp c.0, b0					; read DS18B20 temperature, degree C
    	#ifdef simulating					; when simulating ...
    	  b0 = 20						;   force temperature to 20C
    	#endif
    	b1 = b0 * 18 + 5 / 10 + 32				; calculate degree F, F = C * 1.8 + 32
    	serout b.0, n2400, ( #b0, "C=", #b1, "F", cr, lf )	; display temperatures
    	pause 5000						; wait 5 seconds
    	goto main						; loop back to start
    Copy Code Submit an Example

    Submit Your Own Code!

    You must be logged in to submit code examples. Login now.

    Comments

    • Login to leave a comment.