one button, three relays.

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
dido8884
New user
Posts: 3
Joined: 23 Nov 2022, 18:29

one button, three relays.

#1 Post by dido8884 » 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.

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

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: one button, three relays.

#2 Post by Ath » 23 Nov 2022, 19:43

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
/Ton (PayPal.me)

dido8884
New user
Posts: 3
Joined: 23 Nov 2022, 18:29

Re: one button, three relays.

#3 Post by dido8884 » 23 Nov 2022, 20:28

thanks, helped a lot. 8 hours trying to understand. ;)

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 34 guests