PE6 #include

jims

Senior Member
I'm trying to use the PE6 #include function. Have created the attached program & both Macros work as expected. Here's the rub....I can't seem to include either macro in a new program using the #include function. Get error when check syntex. Need help please. thank you Jims

Code:
[color=Green]'###############################
'#Test #macro with 20m2
'#Use IR clicker to enter data
'#& show on OLED display.
'##############################

 [/color][color=Navy]#picaxe [/color][color=Black]20m2
 [/color][color=Blue]pause [/color][color=Navy]1000
 [/color][color=Blue]serout B.0[/color][color=Black], [/color][color=Blue]n2400[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]1[/color][color=Blue])
 pause [/color][color=Navy]30
 
 [/color][color=Blue]symbol [/color][color=Black]oled_pin [/color][color=DarkCyan]= [/color][color=Blue]B.0
 symbol [/color][color=Black]ir_clicker[/color][color=DarkCyan]=[/color][color=Blue]B.1
 symbol [/color][color=Black]sw_1[/color][color=DarkCyan]=[/color][color=Purple]pinB.2
 [/color][color=Blue]symbol [/color][color=Black]irdata[/color][color=DarkCyan]= [/color][color=Purple]b0
 [/color][color=Blue]symbol [/color][color=Black]ir_temp[/color][color=DarkCyan]=[/color][color=Purple]b1
 [/color][color=Blue]symbol [/color][color=Black]data_mem[/color][color=DarkCyan]=[/color][color=Navy]0
 [/color][color=Blue]symbol [/color][color=Black]data_mem1[/color][color=DarkCyan]=[/color][color=Navy]1
 [/color][color=Blue]symbol [/color][color=Black]data_mem2[/color][color=DarkCyan]=[/color][color=Navy]2
 [/color][color=Blue]symbol [/color][color=Black]position[/color][color=DarkCyan]=[/color][color=Purple]b11
 
  
       [/color][color=Green]'#########################################################################
       '#Macro to receive IR data from a clicker, correct data from numeric keys
       '# & show on a PICAXE 133Y OLED display as it's received.
       '#########################################################################
         
        [/color][color=Navy]#macro [/color][color=Black]clicker[/color][color=Blue]( [/color][color=Black]delay, number  [/color][color=Blue]) 
        serout [/color][color=Black]oled_pin, [/color][color=Blue]n2400[/color][color=Black], [/color][color=Blue]( [/color][color=Navy]254[/color][color=Black], [/color][color=Navy]128[/color][color=Black], [/color][color=Red]"ENTER DATA"[/color][color=Blue])
         irin [/color][color=Black]ir_clicker, irdata
         [/color][color=Blue]if [/color][color=Black]irdata[/color][color=DarkCyan]=<[/color][color=Navy]9 [/color][color=Blue]then let [/color][color=Black]irdata[/color][color=DarkCyan]=[/color][color=Black]irdata[/color][color=DarkCyan]+[/color][color=Navy]1[/color][color=Black]:[/color][color=Blue]endif
         if [/color][color=Black]irdata[/color][color=DarkCyan]=[/color][color=Navy]10 [/color][color=Blue]then let [/color][color=Black]irdata[/color][color=DarkCyan]=[/color][color=Navy]0[/color][color=Black]:[/color][color=Blue]endif
         
         serout [/color][color=Black]oled_pin, [/color][color=Blue]n2400[/color][color=Black], [/color][color=Blue]( [/color][color=Navy]254[/color][color=Black], position, #number, [/color][color=Red]" " [/color][color=Blue])
         pause [/color][color=Black]delay
        [/color][color=Navy]#endmacro 
        
       [/color][color=Green]'#####################################################
       '#Macro waits for switch 1 to be ON.
       '# When switch is ON, wait 50msec to debounce switch.
       '#####################################################
        
        [/color][color=Navy]#macro [/color][color=Black]see_sw_1 
         [/color][color=Blue]do[/color][color=Black]:[/color][color=Blue]loop until [/color][color=Black]sw_1 [/color][color=DarkCyan]is [/color][color=Blue]on   [/color][color=Green]'Loop until switch is ON.
         [/color][color=Blue]pause [/color][color=Navy]50                    [/color][color=Green]'Pause to debounce switch
         [/color][color=Navy]#endmacro[/color]
[color=Black]Main: 

             see_sw_1 
             [/color][color=Blue]let [/color][color=Black]position[/color][color=DarkCyan]=[/color][color=Navy]192
             
            [/color][color=Black]clicker[/color][color=Blue]( [/color][color=Navy]100[/color][color=Black], irdata  [/color][color=Blue]) 
            [/color][color=Black]ir_temp[/color][color=DarkCyan]=[/color][color=Black]irdata[/color][color=DarkCyan]*[/color][color=Navy]100
             
            [/color][color=Blue]inc [/color][color=Black]position
            
            clicker[/color][color=Blue]( [/color][color=Navy]100[/color][color=Black], irdata  [/color][color=Blue]) 
             [/color][color=Black]ir_temp[/color][color=DarkCyan]= [/color][color=Black]irdata[/color][color=DarkCyan]*[/color][color=Navy]10[/color][color=DarkCyan]+[/color][color=Black]ir_temp
              
             [/color][color=Blue]inc [/color][color=Black]position
            
            clicker[/color][color=Blue]( [/color][color=Navy]100[/color][color=Black], irdata  [/color][color=Blue]) 
              [/color][color=Black]ir_temp[/color][color=DarkCyan]= [/color][color=Black]irdata[/color][color=DarkCyan]+[/color][color=Black]ir_temp
               
              [/color][color=Blue]inc [/color][color=Black]position
                  
             [/color][color=Blue]write  [/color][color=Black]data_mem ,  ir_temp [/color][color=Green]'Write irdata to data memory position 0
             
             [/color][color=Blue]serout [/color][color=Black]oled_pin, [/color][color=Blue]n2400[/color][color=Black], [/color][color=Blue]( [/color][color=Navy]254[/color][color=Black], [/color][color=Navy]128[/color][color=Black], [/color][color=Red]"IS THIS OK? "[/color][color=Blue])[/color][color=Black]:[/color][color=Blue]pause [/color][color=Navy]2000
                         
              [/color][color=Blue]serout [/color][color=Black]oled_pin, [/color][color=Blue]n2400[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]192[/color][color=Black],#ir_temp[/color][color=Blue])[/color][color=Black]:[/color][color=Blue]pause [/color][color=Navy]2000
             
             [/color][color=Blue]serout [/color][color=Black]oled_pin, [/color][color=Blue]n2400[/color][color=Black],[/color][color=Blue]([/color][color=Navy]254[/color][color=Black],[/color][color=Navy]1[/color][color=Blue])
             
             pause [/color][color=Navy]1000
                               
             [/color][color=Blue]goto [/color][color=Black]main  [/color]
 
Last edited:

jims

Senior Member
Perhaps a little more info?

- the code that is trying to do the includes
- the error message
Here you are. Will send error message separately.
Code:
[color=Green]'#############################################################
'#Picaxe 20m2 program to try & use #include function in PE6.
'# Macro (see_sw_1) is in program (Test PE6.bas).
'#############################################################[/color]


[color=Blue]symbol [/color][color=Purple]sw_1[/color][color=DarkCyan]=[/color][color=Purple]pinB.1[/color]

[color=Navy]#picaxe [/color][color=Black]20m2[/color]

[color=Green]'#include "see_sw_1"[/color]

[color=Black]main:
      [/color][color=Green]'see_sw_1    'Macro from Test PE6.bas
      [/color][color=Blue]high C.1    [/color][color=Green]'Flip a led to have something to watch.
      [/color][color=Blue]pause [/color][color=Navy]2000
      [/color][color=Blue]low C.1     pause [/color][color=Navy]1000
      [/color][color=Blue]goto [/color][color=Black]main[/color]
 

jims

Senior Member
Here you are. Will send error message separately.
Code:
[color=Green]'#############################################################
'#Picaxe 20m2 program to try & use #include function in PE6.
'# Macro (see_sw_1) is in program (Test PE6.bas).
'#############################################################[/color]


[color=Blue]symbol [/color][color=Purple]sw_1[/color][color=DarkCyan]=[/color][color=Purple]pinB.1[/color]

[color=Navy]#picaxe [/color][color=Black]20m2[/color]

[color=Green]'#include "see_sw_1"[/color]

[color=Black]main:
      [/color][color=Green]'see_sw_1    'Macro from Test PE6.bas
      [/color][color=Blue]high C.1    [/color][color=Green]'Flip a led to have something to watch.
      [/color][color=Blue]pause [/color][color=Navy]2000
      [/color][color=Blue]low C.1     pause [/color][color=Navy]1000
      [/color][color=Blue]goto [/color][color=Black]main[/color]
Here's the error message.
#include "see_sw_1"
^
Syntax error on line 11 at position 1

Error: Can not open the input file.
I couldn't figure out how to include both things that you requested in one reply.
Sorry... Jims
 

geoff07

Senior Member
If the input file name includes .bas or .basinc, then you need to put that in the #include statement. The files need to be in the same folder for it to work without any prefix.
 

Technical

Technical Support
Staff member
Try this:

main file

Code:
[COLOR=Green]'###############################
'#Test #macro with 20m2
'#Use IR clicker to enter data
'#& show on OLED display.
'##############################

 [/COLOR][COLOR=Navy]#picaxe [/COLOR][COLOR=Black]20m2
 [/COLOR][COLOR=Blue]pause [/COLOR][COLOR=Navy]1000
 [/COLOR][COLOR=Blue]serout B.0[/COLOR][COLOR=Black], [/COLOR][COLOR=Blue]n2400[/COLOR][COLOR=Black],[/COLOR][COLOR=Blue]([/COLOR][COLOR=Navy]254[/COLOR][COLOR=Black],[/COLOR][COLOR=Navy]1[/COLOR][COLOR=Blue])
 pause [/COLOR][COLOR=Navy]30
 
[/COLOR]#include "test.basinc"

[COLOR=Black]Main: 

             see_sw_1 
             [/COLOR][COLOR=Blue]let [/COLOR][COLOR=Black]position[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Navy]192
             
            [/COLOR][COLOR=Black]clicker[/COLOR][COLOR=Blue]( [/COLOR][COLOR=Navy]100[/COLOR][COLOR=Black], irdata  [/COLOR][COLOR=Blue]) 
            [/COLOR][COLOR=Black]ir_temp[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Black]irdata[/COLOR][COLOR=DarkCyan]*[/COLOR][COLOR=Navy]100
             
            [/COLOR][COLOR=Blue]inc [/COLOR][COLOR=Black]position
            
            clicker[/COLOR][COLOR=Blue]( [/COLOR][COLOR=Navy]100[/COLOR][COLOR=Black], irdata  [/COLOR][COLOR=Blue]) 
             [/COLOR][COLOR=Black]ir_temp[/COLOR][COLOR=DarkCyan]= [/COLOR][COLOR=Black]irdata[/COLOR][COLOR=DarkCyan]*[/COLOR][COLOR=Navy]10[/COLOR][COLOR=DarkCyan]+[/COLOR][COLOR=Black]ir_temp
              
             [/COLOR][COLOR=Blue]inc [/COLOR][COLOR=Black]position
            
            clicker[/COLOR][COLOR=Blue]( [/COLOR][COLOR=Navy]100[/COLOR][COLOR=Black], irdata  [/COLOR][COLOR=Blue]) 
              [/COLOR][COLOR=Black]ir_temp[/COLOR][COLOR=DarkCyan]= [/COLOR][COLOR=Black]irdata[/COLOR][COLOR=DarkCyan]+[/COLOR][COLOR=Black]ir_temp
               
              [/COLOR][COLOR=Blue]inc [/COLOR][COLOR=Black]position
                  
             [/COLOR][COLOR=Blue]write  [/COLOR][COLOR=Black]data_mem ,  ir_temp [/COLOR][COLOR=Green]'Write irdata to data memory position 0
             
             [/COLOR][COLOR=Blue]serout [/COLOR][COLOR=Black]oled_pin, [/COLOR][COLOR=Blue]n2400[/COLOR][COLOR=Black], [/COLOR][COLOR=Blue]( [/COLOR][COLOR=Navy]254[/COLOR][COLOR=Black], [/COLOR][COLOR=Navy]128[/COLOR][COLOR=Black], [/COLOR][COLOR=Red]"IS THIS OK? "[/COLOR][COLOR=Blue])[/COLOR][COLOR=Black]:[/COLOR][COLOR=Blue]pause [/COLOR][COLOR=Navy]2000
                         
              [/COLOR][COLOR=Blue]serout [/COLOR][COLOR=Black]oled_pin, [/COLOR][COLOR=Blue]n2400[/COLOR][COLOR=Black],[/COLOR][COLOR=Blue]([/COLOR][COLOR=Navy]254[/COLOR][COLOR=Black],[/COLOR][COLOR=Navy]192[/COLOR][COLOR=Black],#ir_temp[/COLOR][COLOR=Blue])[/COLOR][COLOR=Black]:[/COLOR][COLOR=Blue]pause [/COLOR][COLOR=Navy]2000
             
             [/COLOR][COLOR=Blue]serout [/COLOR][COLOR=Black]oled_pin, [/COLOR][COLOR=Blue]n2400[/COLOR][COLOR=Black],[/COLOR][COLOR=Blue]([/COLOR][COLOR=Navy]254[/COLOR][COLOR=Black],[/COLOR][COLOR=Navy]1[/COLOR][COLOR=Blue])
             
             pause [/COLOR][COLOR=Navy]1000
                               
             [/COLOR][COLOR=Blue]goto [/COLOR][COLOR=Black]main  [/COLOR]
and this is what is in test.basinc

Code:
[COLOR=Blue]symbol [/COLOR][COLOR=Black]oled_pin [/COLOR][COLOR=DarkCyan]= [/COLOR][COLOR=Blue]B.0
 symbol [/COLOR][COLOR=Black]ir_clicker[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Blue]B.1
 symbol [/COLOR][COLOR=Black]sw_1[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Purple]pinB.2
 [/COLOR][COLOR=Blue]symbol [/COLOR][COLOR=Black]irdata[/COLOR][COLOR=DarkCyan]= [/COLOR][COLOR=Purple]b0
 [/COLOR][COLOR=Blue]symbol [/COLOR][COLOR=Black]ir_temp[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Purple]b1
 [/COLOR][COLOR=Blue]symbol [/COLOR][COLOR=Black]data_mem[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Navy]0
 [/COLOR][COLOR=Blue]symbol [/COLOR][COLOR=Black]data_mem1[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Navy]1
 [/COLOR][COLOR=Blue]symbol [/COLOR][COLOR=Black]data_mem2[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Navy]2
 [/COLOR][COLOR=Blue]symbol [/COLOR][COLOR=Black]position[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Purple]b11
 
  
       [/COLOR][COLOR=Green]'#########################################################################
       '#Macro to receive IR data from a clicker, correct data from numeric keys
       '# & show on a PICAXE 133Y OLED display as it's received.
       '#########################################################################
         
        [/COLOR][COLOR=Navy]#macro [/COLOR][COLOR=Black]clicker[/COLOR][COLOR=Blue]( [/COLOR][COLOR=Black]delay, number  [/COLOR][COLOR=Blue]) 
        serout [/COLOR][COLOR=Black]oled_pin, [/COLOR][COLOR=Blue]n2400[/COLOR][COLOR=Black], [/COLOR][COLOR=Blue]( [/COLOR][COLOR=Navy]254[/COLOR][COLOR=Black], [/COLOR][COLOR=Navy]128[/COLOR][COLOR=Black], [/COLOR][COLOR=Red]"ENTER DATA"[/COLOR][COLOR=Blue])
         irin [/COLOR][COLOR=Black]ir_clicker, irdata
         [/COLOR][COLOR=Blue]if [/COLOR][COLOR=Black]irdata[/COLOR][COLOR=DarkCyan]=<[/COLOR][COLOR=Navy]9 [/COLOR][COLOR=Blue]then let [/COLOR][COLOR=Black]irdata[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Black]irdata[/COLOR][COLOR=DarkCyan]+[/COLOR][COLOR=Navy]1[/COLOR][COLOR=Black]:[/COLOR][COLOR=Blue]endif
         if [/COLOR][COLOR=Black]irdata[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Navy]10 [/COLOR][COLOR=Blue]then let [/COLOR][COLOR=Black]irdata[/COLOR][COLOR=DarkCyan]=[/COLOR][COLOR=Navy]0[/COLOR][COLOR=Black]:[/COLOR][COLOR=Blue]endif
         
         serout [/COLOR][COLOR=Black]oled_pin, [/COLOR][COLOR=Blue]n2400[/COLOR][COLOR=Black], [/COLOR][COLOR=Blue]( [/COLOR][COLOR=Navy]254[/COLOR][COLOR=Black], position, #number, [/COLOR][COLOR=Red]" " [/COLOR][COLOR=Blue])
         pause [/COLOR][COLOR=Black]delay
        [/COLOR][COLOR=Navy]#endmacro 
        
       [/COLOR][COLOR=Green]'#####################################################
       '#Macro waits for switch 1 to be ON.
       '# When switch is ON, wait 50msec to debounce switch.
       '#####################################################
        
        [/COLOR][COLOR=Navy]#macro [/COLOR][COLOR=Black]see_sw_1 
         [/COLOR][COLOR=Blue]do[/COLOR][COLOR=Black]:[/COLOR][COLOR=Blue]loop until [/COLOR][COLOR=Black]sw_1 [/COLOR][COLOR=DarkCyan]is [/COLOR][COLOR=Blue]on   [/COLOR][COLOR=Green]'Loop until switch is ON.
         [/COLOR][COLOR=Blue]pause [/COLOR][COLOR=Navy]50                    [/COLOR][COLOR=Green]'Pause to debounce switch
         [/COLOR][COLOR=Navy]#endmacro
[/COLOR]
 

Technical

Technical Support
Staff member
And if you are really confused turn on 'display preprocessor output file' under File>options>diagnostics.

You can then see the combined result of what using the #include actually produces.
 

jims

Senior Member
And if you are really confused turn on 'display preprocessor output file' under File>options>diagnostics.

You can then see the combined result of what using the #include actually produces.
I am really confused at this point. However, I'll try to struggle through it for a while longer. Right now windows is telling me that it needs a file association in order to open these files. Earlier when I tried to open one of the files, it opened in PE5. I'm so screwed-up now I just need to back away & come back later to read your comments and start a-fresh. Thank you for sticking with me. I'll be back when the "fog" clears out of my brain. Jims
 

Technical

Technical Support
Staff member
We think you are thinking it is harder than it is!

Open the original file that has everything in.
Select the macros and use Edit>Cut
Click File>New>New Include and Edit>Paste this text in. Save the file as test.basinc in the same folder as the original
In the original file add the one line #include "test.basinc" where the macros were removed.

That is it!
 

jims

Senior Member
We think you are thinking it is harder than it is!

Open the original file that has everything in.
Select the macros and use Edit>Cut
Click File>New>New Include and Edit>Paste this text in. Save the file as test.basinc in the same folder as the original
In the original file add the one line #include "test.basinc" where the macros were removed.

That is it!
I must have this thing badly compromised. When I tried your suggestion, got the white screen with the red X thru the center & it sent an error report to you. Tomorrow I will start from scratch with a fresh PE6 download & create simpler programs to try the # macro & #include functions. thank you again for your patience. Jims
 

jims

Senior Member
This does it.

We think you are thinking it is harder than it is!

Open the original file that has everything in.
Select the macros and use Edit>Cut
Click File>New>New Include and Edit>Paste this text in. Save the file as test.basinc in the same folder as the original
In the original file add the one line #include "test.basinc" where the macros were removed.

That is it!
Thank you!! I reloaded the PE6 and used your suggestion. Works GREAT!! With this approach, I plan to set-up a file as my MACRO library.
Part of my problem yesterday was that I didn't understand about saving the "work space" vs saving as a file & I got all tangled-up (learning process). Much obliged for your patience.
Jims
 

jims

Senior Member
Thanks, Technical. I just got around to trying this. Shows exactly what #Macro does with the code. Good tool to help evaluate what happens with "Macro vs Sub-routines". Jims
And if you are really confused turn on 'display preprocessor output file' under File>options>diagnostics.

You can then see the combined result of what using the #include actually produces.
 

newplumber

Senior Member
Hi
I just found this post and thanks technical
I am impressed at how easy it is use...still learning #macro but do see light at the end of the tunnel
my code for no OLED/no LCD with just 3 leds connected to pins b.1...b.2...b3...with each having 470 ohm resistor to ground
on a picaxe 20m2 (funny how it still shows i am misspelling picaxe...wants it to be picante whatever that means)

copy/paste/save this first code under HOME tab click "New" scroll down to "New BASIC Include(*.basinc)" and save as flashledtest.basinc
or technical's way " Click File>New>New Include and Edit>Paste this text in. Save the file as flashledtest.basinc in the same folder
Code:
#macro FLASH_LED_B_1 
high b.1
pause 50
low b.1
pause 500
#endmacro

#macro FLASH_LED_B_2 
high b.2
pause 50
low b.2
pause 500
#endmacro

#macro FLASH_LED_B_3 
high b.3
pause 50
low b.3
pause 500
#endmacro

#macro break_time 
pause 1000
#endmacro

#macro FLASH_ALL_3 
high b.3 :high b.2 : high b.1
pause 50
low b.3 :low b.2 : low b.1
pause 500
#endmacro
Then click Home tab , New, New BASIC(*.bas) and save as flashledtestmain.bas
(make sure its in the same folder) copy/paste/save code below and should work
Code:
#picaxe 20m2
#include "flashledtest.basinc"

DO 
   flash_led_b_1
   flash_led_b_2
   flash_led_b_3
   break_time
   flash_all_3
   break_time
LOOP
This is how I have did a simple test which works well of course with out any comments in the code
but I have to say it sure looks different from my normal codes
thanks again and back to learning/pretending to learn
 

lbenson

Senior Member
Because you can pass a parameter (e.g., a pin number) to a macro, you don't need to define a separate macro for each pin:
Code:
#picaxe 20m2

#macro FLASH_LED(pPin)
high pPin
pause 50
low pPin
pause 500
#endmacro

DO 
   flash_led(b.1)
   flash_led(b.2)
   flash_led(b.3)
   pause 2000
LOOP
You could also extend this to include ON_TIME and OFF_TIME as parameters (modifying your pauses accordingly, e.g., PAUSE ON_TIME).
 

hippy

Technical Support
Staff member
And further to what lbenson adds, you can have macros invoking other macros so ...

Code:
#Macro TurnLedOnThenOff(pin,onTime,offTime)
  High pin : Pause onTime
  Low  pin : Pause offTime
#EndMacro

#Macro FlashLed(pin)
  TurnLedOnThenOff(pin,50,500)
#EndMacro

FlashLed(B.1)
FlashLed(B.2)
 

newplumber

Senior Member
Thanks lbenson,hippy ... another trick in the book
now I am slowly understanding how #Macro can make it more understandable
btw maybe there is some post about this code below ... but
why can't you shorten the #macros lines like I.E.

Code:
flashled(b.1):flashled(b.2)
it gives Error:syntax error and not that its ever been a problem but just curious
 

hippy

Technical Support
Staff member
Macros force CR-LF at their end to avoid incorrect code generation but that then causes a syntax error with the ":" separator which is not allowed to start a new line. What you effectively have, as the pre-processor expands it, is...

Code:
flashled(b.1)
:flashled(b.2)
However, due to the way expansions are done and the way everything gets handled, you can put two macros on one line by simply not including the ":" ...

Code:
flashled(b.1) flashled(b.2)
 
Top