How to setup counter in code
-
@oliof said in How to setup counter in code:
var endstop0_triggers = 0 var endstop1_triggers = 1
why enstop1 triger value starts from 1 and not 0
-
@martin7404 a simple typo.
-
@oliof One more thing
I have to define enstops in config.g or not -
@martin7404 you can define them wherever you want, config.g is the normal place. They need to be defined before you use them of course.
Another option would be to define them as triggers and have trigger2 to trigger9 macros that write to a file whenever they are actuated (triggers 0 and 1 are special cases)
-
@oliof thank you , this is what i meant to define them like triggers
-
-
@oliof HI,
I am finaly setup and as far I am not good in meta commands here it isM32 "0:/gcodes/test.g" File 0:/gcodes/test.g selected for printing Error: Bad command: endstop0_triggers = endstop0_triggers+1 Error: in GCode file line 16 column 6: meta command: missing array index Cancelled printing file 0:/gcodes/test.g, print time was 0h 0m
I did checke the spelling 3 times no luck
-
@martin7404 my mistake, replace
endstop0_triggers = endstop0_triggers+1
with
set endstop0_triggers = {endstop0_triggers+1}
and see if that works. Same for the other equivalent lines.
-
@oliof
Finaly get it working
Here it isvar endstop0_triggers=0 var endstop1_triggers = 0 var endstop2_triggers = 0 var endstop3_triggers = 0 var endstop4_triggers = 0 var endstop5_triggers = 0 var endstop6_triggers = 0 var endstop7_triggers = 0; while iterations <30 M106 S1.0 if sensors.endstops[0].triggered set var.endstop0_triggers = {var.endstop0_triggers+1} ; ; if sensors.endstops[1].triggered ; endstop1_triggers = {endstop1_triggers+1} ; G4 P400 M106 S0 G4 P500 ; this adds a 1 second pause, if you want to measure every second, measure your cycle time and reduce the pause accordingly echo var.endstop0_triggers echo >>"sys/counts" var.endstop0_triggers
-
@oliof thank you
-
@martin7404 your current version only counts the first endstop. You'll need to duplicate line 13/14 and adjust for endstop1-endstop8 in there to count the others too.