Page 1 of 1

one button, three relays.

Posted: 23 Nov 2022, 18:57
by dido8884
Help with the rules, I want to control three relays with one button. Each press turns on the next relays and so on in a circle. How to implement this? There used to be such rules, now they do not work.

Code: Select all

on prg#prg do
if [prg#prg]=0 and [sw2_p1#sw2_p1]=0 and [sw3_p2#sw3_p2]=0 and [sw4_p3#sw4_p3]=0
 gpio,14,0
 gpio,12,0
 gpio,4,1
 
endif
endon
on prg#prg= do
 if [prg#prg]=0 and [sw2_p1#sw2_p1]=1 and [sw3_p2#sw3_p2]=0 and [sw4_p3#sw4_p3]=0
 gpio,4,0
 gpio,12,1
 gpio,14,0
 
 endif
endon
on prg#prg do
 if [prg#prg]=0 and [sw2_p1#sw2_p1]=0 and [sw3_p2#sw3_p2]=1 and [sw4_p3#sw4_p3]=0
 gpio,12,0
 gpio,4,0
 gpio,14,1
 endif
endon
on prg#prg do
 if [prg#prg]=0 and [sw2_p1#sw2_p1]=0 and [sw3_p2#sw3_p2]=0 and [sw4_p3#sw4_p3]=1
 gpio,4,0
 gpio,14,0
 gpio,12,0
 endif
endon

Re: one button, three relays.

Posted: 23 Nov 2022, 19:43
by Ath
dido8884 wrote: 23 Nov 2022, 18:57 Help with the rules, I want to control three relays with one button. Each press turns on the next relays and so on in a circle. How to implement this? There used to be such rules, now they do not work.
Because of Rules caching this can no longer be used, but your code can be easily corrected:

Code: Select all

on prg#prg do
  if [prg#prg]=0 and [sw2_p1#sw2_p1]=0 and [sw3_p2#sw3_p2]=0 and [sw4_p3#sw4_p3]=0
    gpio,14,0
    gpio,12,0
    gpio,4,1
  endif
  if [prg#prg]=0 and [sw2_p1#sw2_p1]=1 and [sw3_p2#sw3_p2]=0 and [sw4_p3#sw4_p3]=0
    gpio,4,0
    gpio,12,1
    gpio,14,0
  endif
  if [prg#prg]=0 and [sw2_p1#sw2_p1]=0 and [sw3_p2#sw3_p2]=1 and [sw4_p3#sw4_p3]=0
    gpio,12,0
    gpio,4,0
    gpio,14,1
  endif
  if [prg#prg]=0 and [sw2_p1#sw2_p1]=0 and [sw3_p2#sw3_p2]=0 and [sw4_p3#sw4_p3]=1
    gpio,4,0
    gpio,14,0
    gpio,12,0
  endif
endon

Re: one button, three relays.

Posted: 23 Nov 2022, 20:28
by dido8884
thanks, helped a lot. 8 hours trying to understand. ;)