Is the logic different between models?

Discussion in 'Pascal Logic Code Examples' started by zei20t, Apr 22, 2020.

  1. zei20t

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    88
    Likes Received:
    0
    Location:
    Sydney, Australia
    I found some code i had working a few years ago on my old touch screen. the same code, adjusted GAs, gives me errors on my Wiser2.

    Here is what im attempting:

    once GetLightingState("PIR Ensuite") = ON then
    begin
    if (time > sunset) and (time < "10:15PM") then
    begin
    SetLightingLevel("Ensuite Toilet", 100%, "2s");
    end
    if (time > "10:15PM") and (time < sunrise) then
    begin
    SetLightingLevel("Ensuite Toilet", 30%, "4s");
    end
    end;

    once GetLightingState("PIR Ensuite") = OFF then
    begin
    SetLightingLevel("Ensuite Toilet", 0%, "8s");
    end;

    I'm getting an illegal symbol, but i cant work out what it is:

    Error C006 at line 32:3 - Illegal symbol
    Error C006 at line 32:3 - Illegal symbol

    Line 32 doesnt exist.

    Anyone got an ideas what ive done wrong please?
     
    zei20t, Apr 22, 2020
    #1
    1. Advertisements

  2. zei20t

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,060
    Likes Received:
    92
    Location:
    Adelaide, Australia
    You need a semi-colon after the first "end" statement to finish the statement.

    The error is confusing because the compiler isn't seeing a matching end for the first "begin" so keeps looking until it has gone through all the code for all the modules.

    While you can get away with no semi-colon after the second end because it is followed by another end, I suggest you always add a semi-colon after every end. Unneeded ones will be ignored and will stop further confusion if you add more code between the 2 ends.

    Wow...That was a lot of ends :)
     
    Ashley, Apr 22, 2020
    #2
    zei20t likes this.
    1. Advertisements

  3. zei20t

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,060
    Likes Received:
    92
    Location:
    Adelaide, Australia
    Oh, and by the way, that code won't work anyway.

    The statement if (time > "10:15PM") and (time < sunrise) can never be true. How can it be after 10pm and before sunrise on the same day?

    Try (time > "10:15PM") or (time < sunrise) then ...; This will match periods 10:15pm to 23:59:59 and 00:00 to sunrise which is what you really want.
     
    Ashley, Apr 23, 2020
    #3
    zei20t likes this.
  4. zei20t

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    88
    Likes Received:
    0
    Location:
    Sydney, Australia
    Thanks for your help, the missing semi-colon fixed compilation

    as for the logic, ahh that makes complete sense using 'or' i haven't tested it yet after midnight, so thanks again for your help!

    im not good with code, i tried my hand at using the SHAC for logic, it was even harder for me haha
     
    zei20t, Apr 23, 2020
    #4
  5. zei20t

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    88
    Likes Received:
    0
    Location:
    Sydney, Australia
    So the time thing didn't want to work properly, i realise i enable and disable the PIRs at the time i want so dont need to specify the other time threshold as the sensor wont be active, ended up with this code:

    once GetLightingState("PIR Ensuite") = ON then
    begin
    if (time < "9:45PM") then
    begin
    SetLightingLevel("Ensuite Toilet", 100%, "2s");
    end
    else
    begin
    SetLightingLevel("Ensuite Toilet", 10%, "4s");
    end;
    end;

    once GetLightingState("PIR Ensuite") = OFF then
    begin
    SetLightingLevel("Ensuite Toilet", 0%, "8s");
    end;
     
    zei20t, Apr 23, 2020
    #5
  6. zei20t

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,060
    Likes Received:
    92
    Location:
    Adelaide, Australia
    You don't actually need all those begin/ends. They are only needed when you want to have more than one statement after a Once or If.

    Code:
    once GetLightingState("PIR Ensuite") = ON then
        if (time < "9:45PM") then
              SetLightingLevel("Ensuite Toilet", 100%, "2s")
        else
             SetLightingLevel("Ensuite Toilet", 10%, "4s");
    
    once GetLightingState("PIR Ensuite") = OFF then
         SetLightingLevel("Ensuite Toilet", 0%, "8s");
     
    Ashley, Apr 23, 2020
    #6
  7. zei20t

    zei20t

    Joined:
    Aug 18, 2010
    Messages:
    88
    Likes Received:
    0
    Location:
    Sydney, Australia
    wow, ok as you can see im a beginner at this. thank you again!

    and ill need to set the two time contraints in the if statement as i realise after midnight its before 9:45pm
     
    zei20t, Apr 23, 2020
    #7
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.