Shop OBEX P1 Docs P2 Docs Learn Events
Can some look at this routine (DO WHILE IN3 = 0 AND DO WHILE IN3 = 1 ) PROBLE — Parallax Forums

Can some look at this routine (DO WHILE IN3 = 0 AND DO WHILE IN3 = 1 ) PROBLE

sam_sam_samsam_sam_sam Posts: 2,286
edited 2008-07-18 00:41 in General Discussion
I going to use this to log Running Time·or·OFF Time depending which setting·I am using·.......... For A\C units and other·equipment as well


DO WHILE IN3 = 0············ ·' This is mode # 1

Power_ON:

·DO WHILE IN2 = 0············· ' This the routine for mode # 1

GOSUB Display_Time:
·LOOP

DO WHILE IN2 = 1

GOSUB Show_Time
GOSUB Show_State_Input

LOOP

GOSUB Halt_clock
GOSUB Restart_clock
GOSUB Power_Restarts
GOSUB Power_ON

LOOP







DO WHILE IN3 = 1························ ·' This mode # 2

Power_Off:

DO

·GOSUB Show_Time
·······························
·GOSUB Show_State_Input

·LOOP UNTIL IN2 = 1············ ' This is the routine for· mode # 2

·DO

GOSUB Halt_clock

LOOP UNTIL IN2 = 0

GOSUB Restart_clock
GOSUB Power_restarts:
GOSUB Power_Off
·
LOOP

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 7/18/2008 1:03:47 AM GMT

Comments

  • MarkSMarkS Posts: 342
    edited 2008-07-17 14:01
    Kinda hard to help if we don't know what the problem is...
  • FranklinFranklin Posts: 4,747
    edited 2008-07-17 15:02
    Have you tried converting this to a flowchart so you can follow the logic? I think your DO LOOPs are getting confused. Like MarkS says whats wrong and I will add what is it you expect it to do?

    As to your question, if you don't add some form of debounce it will give you a problem.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-07-17 15:35
    I see two problems:

    In the red code, just before LOOP of DO WHILE IN3=0, you GOSUB Power_ON,
    which is already part of that DO WHILE, so this will lead to stack overflow.

    In the blue code, just before LOOP of DO WHILE IN3=1, you GOTO Power_OFF,
    which is already part of that DO WHILE, so you·never get back to the DO WHILE
    to check IN3, and therefore the loop never exits.

    regards peter
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-07-17 19:03
    Peter Verkaik·and MarkS

    Thank you for your reply

    Input 3 will be a switch which will be on one mode or the other

    ······ DO WHILE IN3=0 And· ·DO WHILE IN3=1,

    There are·two··different mode and two··different· routines


    ······ Mode 1 (Power_ON)
    One is for keep track of time·while·unit is running

    Flow chart
    1) check to see if there is power on input # 2
    If·YES then·RUN Clock
    If NO then STOP Clock



    ······· Mode 2 (Power_OFF)
    Two is for keeping track of time while unit is OFF
    Flow Chart
    1) check to see if there is power on input 2
    If NO then·RUN clock
    If YES then STOP Clock

    I·can only use·one mode at a time

    It work the way·I want it to

    I just was not sure if this was the right way to do it or not




    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 7/17/2008 7:31:42 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-07-17 20:25
    Sam_Sam_Sam,

    It sounds like you need logic more along the lines of…

    DO
     
    IF condition1 = 0 THEN
       'your code here
       EXIT
    ELSE
       'your code here
       EXIT
    ENDIF
     
    LOOP
     
    ' Rest of program
    

    You may not need both EXIT statements...One conditional may require you to stay in the loop...But I woldn't use multiple DO...LOOP conditionals...If you intend to stay in the loop excpet for one specific event then exit the loop as shown above but in the right conditional.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support


    Post Edited (Chris Savage (Parallax)) : 7/17/2008 8:30:19 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-07-18 00:41
    Chris

    Thanks· that just what I need this works alot better




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 7/18/2008 12:54:53 AM GMT
Sign In or Register to comment.