input and save input

Status
Not open for further replies.
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
IF Player1 = true
THEN led1 = 1
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.
IF Player2 = true
THEN led5 = 1
DELAYMS(et_time)
TOGGLE (led2)
END IF


IF Player3= true
THEN led6 = 1
DELAYMS(et_time)
TOGGLE (led3)
END IF
etc.
 
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:
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
 
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.
 
....the idea I was rolling around but would entail 10 sub routes, one per switch position.....

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.
 
MrDEB, I think 10 subroutines is an excellent idea. Nine more things to go wrong.

Mike.
 
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.

 
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.
SUB pos1()
for x = 0 to 10
Led1 = 1
DELAYMS(ET_time/2)
TOGGLE (Led1)
if switch1=0 then break
end if
next
END SUB

IF Player1 = true
THEN pos1()
END IF
 
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.

 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…