1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

input and save input

Discussion in 'Microcontrollers' started by MrDEB, Nov 7, 2017.

  1. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    I tried the EXIT and after reading the help file I see why.
    Will try and explain it better. Post #338 says it all why it didn't work.
    the code starts progressing through the TRUE,IF THEN statements
    Then if the player who has their Led on, in this case led1, presses their switch1,before DELAYMS(et_time) is completed. the code ends at that point and goes to the next TRUE,IF THEN statement. In this example etc.
    etc.
     
  2. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,629
    Likes:
    145
    Location:
    Seattle, WA
    In the hopes that this may be finished in time for Christmas.....

    MrDEB,

    Here is your subroutine to "elect" players (elected means that position is playing). This is a little bit of a brute force approach but it will work well. You need to set the right states (high or low) for LED on & off and for switches being pressed and dimension the variables, LEDs and switches. Do not add another Dim statement for Finished - that is done within the subroutine.

    Briefly:

    All the player LEDs are turned off at the start of the subroutine. The Boolean variable Finished is defined and set to false.

    Switches are tested in a While/Wend loop. The ten player switches elect the respective player and light his LED. When the Finished switch is pressed, the Boolean variable Finished is set to true, the While/Wend loop is satisfied and exited.

    Player LEDs are turned off, and the subroutine exited.

    If the ElectedPlayerN = true, that position is playing.

    Code (text):


    sub PlayerElection()
        Dim Finished as Boolean
        Finished = false
        LEDPlayer1 = off
        LEDPlayer2 = off
        LEDPlayer3 = off
        LEDPlayer4 = off
        LEDPlayer5 = off
        LEDPlayer6 = off
        LEDPlayer7 = off
        LEDPlayer8 = off
        LEDPlayer9 = off
        LEDPlayer10 = off
        ElectedPlayer1 = false
        ElectedPlayer2 = false
        ElectedPlayer3 = false
        ElectedPlayer4 = false
        ElectedPlayer5 = false
        ElectedPlayer6 = false
        ElectedPlayer7 = false
        ElectedPlayer8 = false
        ElectedPlayer9 = false
        ElectedPlayer10 = false
     
     
        While Finished = false
         
            If SwitchPlayer1 = pressed then
                LEDPlayer1 = on
                ElectedPlayer1 = true
            End If    
         
            If SwitchPlayer2 = pressed then
                LEDPlayer2 = on
                ElectedPlayer2 = true
            End If    
         
            If SwitchPlayer3 = pressed then
                LEDPlayer3 = on
                ElectedPlayer3 = true
            End If    
         
            If SwitchPlayer4 = pressed then
                LEDPlayer4 = on
                ElectedPlayer4 = true
            End If    
         
            If SwitchPlayer5 = pressed then
                LEDPlayer5 = on
                ElectedPlayer5 = true
            End If    
         
            If SwitchPlayer6 = pressed then
                LEDPlayer6 = on
                ElectedPlayer6 = true
            End If    
         
            If SwitchPlayer7 = pressed then
                LEDPlayer7 = on
                ElectedPlayer7 = true
            End If    
         
            If SwitchPlayer8 = pressed then
                LEDPlayer8 = on
                ElectedPlayer8 = true
            End If    
         
            If SwitchPlayer9 = pressed then
                LEDPlayer9 = on
                ElectedPlayer9 = true
            End If    
         
            If SwitchPlayer10 = pressed then
                LEDPlayer10 = on
                ElectedPlayer10 = true
            End If    
         
            If SwitchFinished = pressed then
                Finished = true
            End If
         
        Wend 'Finished switch has been pressed.  Exit loop
         
        'turn out the lights and go away
         
        LEDPlayer1 = off
        LEDPlayer2 = off
        LEDPlayer3 = off
        LEDPlayer4 = off
        LEDPlayer5 = off
        LEDPlayer6 = off
        LEDPlayer7 = off
        LEDPlayer8 = off
        LEDPlayer9 = off
        LEDPlayer10 = off
     
    End Sub
     
     
     
  3. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    A sub route is what I was thinking this morning but had other honey do's to complete first. Will try your suggestion as well as the idea I was rolling around but would entail 10 sub routes, one per switch position.
    Thanks, will run your suggestion.
     
  4. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10
  5. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,629
    Likes:
    145
    Location:
    Seattle, WA
    Make some effort to understand what I took my time to write for you. I explained each step fully so you should be able to follow it.
     
  6. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,710
    Likes:
    421
    Location:
    Brisbane Australia
    ONLINE
    MrDEB, I think 10 subroutines is an excellent idea:D. Nine more things to go wrong.

    Mike.
     
  7. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,629
    Likes:
    145
    Location:
    Seattle, WA
    It is kind of special to have the code I spent my time working on snubbed by someone who thinks 10 separate sub routes would be a better answer.

    Of course we are only on page 18 of this thread. I'm pretty sure I guessed 50 didn't I? I think I said 50.

    MrDEB, since you can't even make an if/then statement with without extreme difficulty, maybe you should try to understand what others are recommending without getting creative.

    aviary-image-1519181530745.jpeg
     
  8. dave miyares

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    2
    Likes:
    -10
  9. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    I ran your suggestion Jon and it kinda works but the Led stay on when their supposed to be off. I had to make some wholesale changes to compile with my code to date. Minor adjustments such as LedPlayer1 = on changed to led1=1. Got it to compile and run but needs some tweeking. I like where you are going with the code and going to get it to work as desired.
    In the mean time I was still hooked on the BREAK statement and got it to work good but needs tweeking as well. One minor flaw is I need 10 sub routes just for the PLAYER=TRUE statements. The FOR NEXT loop is to allow the player to exit and next players led comes on. It isn't pretty but?? Now that I know my concept should work and Chinese new year is over I can order boards.
     
  10. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,629
    Likes:
    145
    Location:
    Seattle, WA
    Of course what I posted tequired you to fill in the details as I had explained.

    If you read the code, you would see that I intended the LEDs to stay on until all players had pushed their buttons to be in the game. How else can you know you're in? When yoi press the done/ready/play button, the LEDs are extinguished as can be easily seen from the code. There's not much code there - you should be able to understand it. It's trivially simple.

    You've entirely missed the concept behind subroutines. Both what the word is, and what it means.

    Screenshot_20180222-091542.jpg
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice