Toggle output/fan using button/trigger?



  • As far as I understand the documentation, it should be possible to connect a simple pushbutton to an unused endstop (E1 for example) and use M581 to have it execute a custom g-code file. I've got a constant current driver for some LED strips in my printer, and I would like to connect them to an unused fan output - they draw about 600 mA, so the current should not be a problem. I don't know how the LED driver would react to being fed PWM input voltage, but then, I don't have to try that... Anyway, I could use M42 to enable or disable the LED. The problem is - I would like to have a toggle button, and as far as I can see, that's not possible at the moment, right? I would have to use a NO/NC switch and trigger on the rising/falling edge to switch the lighting on and off - or is there a way to conditionally branch between two parts of the trigger file?

    (Also, the documentation for M42 reads "See also M583.", but M583 isn't documented - probably a typo?)


  • administrators

    @vwegert, you could use either a single switch and triggers on the rising and falling edges, or a toggle switch connected to 2 endstop inputs.

    Conditional GCode is scheduled for implementation in RRF 2.03.

    Thanks for pointing out the error in the M42 documentation. I've corrected it.



  • Hello.
    Has something changed in this matter?
    I have the same problem: I need to turn on and off with one button (not stable).
    Or maybe it is possible to write a macro to make some g-code depending on the result of checking another g-code?


  • administrators

    I think you can do that by having two M581 trigger numbers attached to the same pin. Each trigger file would turn the fan or led on or off, then disable its own trigger number and enable the other one.



  • Thank you for your response. It's a good idea.
    It works. In config.g I wrote:
    M581 T2 E0 S0;

    and in
    trigger2.g :
    M80 ;
    M581 T2 S-1;
    M581 T3 E0 S0;

    trigger3.g:
    M81
    M581 T3 S-1;
    M581 T2 E0 S0;

    There is one drawback to this solution.
    When the M80 or M81 is executed in a different way, eg via Web or g-code printing, the button must be pressed twice.
    Thank you for your help and I will be grateful for other suggestions.


Log in to reply