Ankündigung

Einklappen
Keine Ankündigung bisher.

Double Switch Logic

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    HS/FS Double Switch Logic

    Trying to figure out what my error is.
    I have this code for a double switch (in the bathroom using the single switch twice on or off within 3 seconds activates the ventilator)
    Code:
    #Reset
    5012|1|"OC[1]"|"0"|""|0|0|1|0
    
    #1ste Aan: 1 in geheugen 1, ingang 2 in tijd 1
    5012|1|"EC[1] and EN[1] == 1 and SN[1] == 0"|"1"|"EN[2]"|0|1|1|0
    
    #1ste Uit: 2 in geheugen 1, ingang 2 in tijd 1
    5012|1|"EC[1] and EN[1] == 0 and SN[1] == 0"|"2"|"EN[2]"|0|1|1|0
    
    #Reset als ingang 1 = 1 en geheugen 1 = 2 en timer 1 loopt
    5012|1|"EC[1] and EN[1] == 1 and SN[1] == 2 and OC[1] == 0"|"0"|"0"|0|1|1|0
    
    #Als ingang 1 = 1 en geheugen 1 = 1 en timer 1 loopt. Zet uitgang 1 op 1. Daarna tijd 1 en geheugen 1 op 0
    5012|0|"EC[1] and EN[1] == 1 and SN[1] == 1 and OC[1] == 0"|"1"|""|1|0|0|0
    5012|1|"EC[1] and EN[1] == 1 and SN[1] == 1 and OC[1] == 0"|"0"|"0"|0|1|1|0
    
    #Reset als ingang 1 = 0 en geheugen 1 = 1 en timer loopt
    5012|1|"EC[1] and EN[1] == 0 and SN[1] == 1 and OC[1] == 0"|"0"|"0"|0|1|1|0
    
    #Als ingang 1 = 0 en geheugen 1 = 2 en timer 1 loopt. Zet uitgang 2 op 1. Daarna tijd 1 en geheugen 1 op 0
    5012|0|"EC[1] and EN[1] == 0 and SN[1] == 2 and OC[1] == 0"|"1"|""|2|0|0|0
    5012|1|"EC[1] and EN[1] == 0 and SN[1] == 2 and OC[1] == 0"|"0"|"0"|0|1|1|0
    Now the code works when i just press on or off twice within 3 seconds and when 1 press once and wait 3 seconds it will act correctly too.
    The problem is when i press on and within 3 seconds i press off, then the 2nd off within 3 seconds wont trigger the output. I have to wait the full seconds before it starts working again.
    What error did i make in the code?

    #2
    The motivation to go through your code is not very high, esp. because of this ugly way one has to write the HS code and you have some lines...

    But I suggest the following:
    Draw a state diagram showing exactly the states you described and the allowed transitions. Than build this state machine using an internal variable holding an ID fo each state to indicate the current state.
    doing this you have a good entry criteria using the current state and nice transitions.
    This approach will also help you debugging because you can check the logic on the paper. When checking the code, you don’t have to think about the logic but you’d if your transfer from paper to code was correct

    Maybe you did this already, as stated in the beginning I didn’t read your code. Sorry but good luck

    Kommentar


      #3
      Zitat von En3rGy Beitrag anzeigen
      The motivation to go through your code is not very high, esp. because of this ugly way one has to write the HS code and you have some lines...
      I could not agree more. Its very painfull at times to write this code for me at least.
      I found the problem however, it was 2 fold:
      1. I stopped calculation with the reset line, i should not have.
      2. Order is important, both reset lines now come before anything else but the line that checks if the timer has expired.

      It now works for both on and off, and in between the reset if i pressed on and right after off.
      So single switch operation will switch the light on or off. And double operation within the time will in my case turn the ventilation on or off.

      Kommentar

      Lädt...
      X