# input and save input

#### MrDEB

##### Well-Known Member
curious question?? a steeper motor instead of an anglouge type gauge using a coil and a needle for pointer?

#### MrDEB

##### Well-Known Member
Boy am I stuck in the dark ages!!
curious if them steeper motors can be used say for a small robot?? like a line following type bot??

#### JonSea

##### Well-Known Member
Probably not. They are designed to move a pointer weighing vitually norhing over a amall arc.

#### JonSea

##### Well-Known Member
Adding some worthwhile content to this epic post, this article from EDN looks at using diode-encoded switch arrays: Encode dozens of buttons with only four lines. It provides good explanations of how diode-encoded switch arrays work, getting as many as 274 switches from just 4 i/o lines.

There are also links to a number of relevant articles as shown below. These links are at the end of the linked article above (i.e., this is just a picture - click above to find these links).

#### MrDEB

##### Well-Known Member
LOTS of interesting info
Thanks. Will start reading as soon as I get done with kitchen project for my wife.

#### MrDEB

##### Well-Known Member
Before I get side tracked I had an idea using the instrument servos. Update the servo clock using 4 instrument servos
One for month, one for day, one for hour and one for miniutes

#### MrDEB

##### Well-Known Member
been hacking away but can'y get the TRUE statements to cooperate .
My goal is each player depresses their button and this "tells" the pic what positions are in play.
I inserted an EXIT and have the subroute as a private sub but after I depress the pos8 button, which is supposed to EXIT the sub route and hopefully save which buttons were depressed, ignoring all the FALSE logic statements. the for next statement is for designating each players button with a number. PLAY() are the leds and pos() are the buttons/switches.
PRIVATE SUB Positions() // select which switches are "IN PLay"
FOR x = 0 TO 5 ignore this for now
IF pos1=0 THEN Player1=true play1=1 DELAYMS(1000) TOGGLE(play1) Switch(T)=index +1 END IF//switch(z) is used as a counter pos? is the switch LOW = enabled
IF pos1=1 THEN Player1=false END IF

IF pos2=0 THEN Player2=true play2=1 DELAYMS(1000) TOGGLE(play2) Switch(T)=index +1 END IF //the FOR NEXT LOOP is used to mark which player position
IF pos2=1 THEN Player2=false END IF

IF pos3=0 THEN Player3=true play3=1 DELAYMS(1000) TOGGLE(play3) Switch(T)=index +1 END IF
IF pos3=1 THEN Player3=false END IF

IF pos4=0 THEN Player4=true play4=1 DELAYMS(1000) TOGGLE(play4) Switch(T)=index +1 END IF
IF pos4=1 THEN Player4=false END IF

IF pos5=0 THEN Player5=true play5=1 DELAYMS(1000) TOGGLE(play5) Switch(T)=index +1 END IF
IF pos5=1 THEN Player5=false END IF

IF pos6=0 THEN Player6=true play6=1 DELAYMS(1000) TOGGLE(play6) Switch(T)=index +1 END IF
IF pos6=1 THEN Player6=false END IF

if pos7=0 THEN Player7=true play7=1 DELAYMS(1000) TOGGLE(play7) Switch(T)=index +1 END IF
IF pos7=1 THEN Player7=false END IF

IF pos8 = 0 THEN play8=1 delayms(3000) toggle (Play8) delayms(500)EXIT END IF //exit su route after all players have depressed their button
NEXT

#### be80be

##### Well-Known Member
I'm not the smartest guy in the boat. But do you know what PRIVATE SUB means just asking?

It means that it's private and only available from within the module it was declared.

So if you want to use it's findings somewhere else that's not going to happen you

probably want Public

Or just a plan inline sub But private kind of means private so the stuff it hold don't mess up the rest of your code.

Kind of a short way of saying it.

The code you posted would be better being a case statement.

Last edited:

#### MrDEB

##### Well-Known Member
I tried a case statement but it turned into a big mess. Am using IF THENS for now. They are one in the same anyway.
will try a public sub route.

#### tumbleweed

##### Active Member
I'm not the smartest guy in the boat
You're plenty smart enough, Burt. At least you know where the boat is.

Here's a stab at reformatting the above that doesn't make my head hurt as much. At least it has a 50-50 shot at compiling.
Code:
sub Positions() // select which switches are "IN PLay"
// set all players false until they press their button
Player1=false
Player2=false
Player3=false
Player4=false
Player5=false
Player6=false
Player7=false

// whatever this is supposed to do, it was done for any switch press
// so might as well just do it here. it likely doesn't work anyway
Switch(T)=index +1

// stay in this loop until switch 8 = 0
while (pos8 = 1)
IF pos1=0 THEN
Player1=true
play1=1               // turn on led (assuming it's an output)
DELAYMS(1000)
play1=0
END IF

IF pos2=0 THEN
Player2=true
play2=1
DELAYMS(1000)
play2=0
END IF

IF pos3=0 THEN
Player3=true
play3=1
DELAYMS(1000)
play3=0
END IF

IF pos4=0 THEN
Player4=true
play4=1
DELAYMS(1000)
play4=0
END IF

IF pos5=0 THEN
Player5=true
play5=1
DELAYMS(1000)
play5=0
END IF

IF pos6=0 THEN
Player6=true
play6=1
DELAYMS(1000)
play6=0
END IF

if pos7=0 THEN
Player7=true
play7=1
DELAYMS(1000)
play7=0
END IF
end while

// signal that we saw switch 8 low and we're exiting
play8=1
delayms(3000)
play8=0
delayms(500)
end sub

#### JonSea

##### Well-Known Member
What's with the indecipherable mess that's supposed to be code?

#### MrDEB

##### Well-Known Member
Thanks Tumbleweed, your posted suggestion makes sense.
I see one of several mistakes I made, by not making player() FALSE.
WILL try out your suggestion and maybe I can go forward with this project.

#### JonSea

##### Well-Known Member
Are you designing this for 7 players or 8? is Play8 the "done selecting, let's go" switch? if not, and Play8 is for the 8th player, why do you base exiting the "election" process on pressing that button?

#### MrDEB

##### Well-Known Member
Only reason I am using only 7 switches is this is a test proyo-type to see if I can get some code actually working as desired.
The end product is a 10 player game. The pcboard has been designed but need to add the Vdd diode and check, recheck etc.
At present, Tumbleweeds suggestion seems to work but need to refine. I like his exit routing using the pos8=0. This will work since the project will utilize 10 player switches and one Lighted switch to indicate when the players turn is timed out and to exit the selection sub route.
I also have a 4 position rotary switch in the mix but that section of code has already been tested and works.

#### MrDEB

##### Well-Known Member
well tumbleweeds suggestion got this code going but trying to exit an IF THEN statement
tried EXIT, END IF, BREAK but none seem to work right.
my objective is progress through a series of IF THEN statements and if the switch() is pressed then the code progress to the next IF THEN code I changed the variables to suggested so switch() instead of pos(), led() instead of play()
contemplating an INTERUPT or FOR NEXT loop? Is this the direction to perform this correctly??
IF Player1 = true
THEN led1 = 1
end if
if switch1=0 then led1 = 0 if the switch1 = 0 then code to jump to next TRUE statement and turn off the led1
exit
DELAYMS(et_time)
TOGGLE (led1)
END IF
IF Player2 = true
THEN led2 = 1
DELAYMS(et_time)
TOGGLE (led2)
END IF

IF Player3 = true
THEN led3 = 1
DELAYMS(et_time)
TOGGLE (led3)
END IF

#### JonSea

##### Well-Known Member
If blah = blah Then
Exit
End If

From the Swordfish doc:

#### Pommie

##### Well-Known Member
Most Helpful Member
You cannot EXIT an IF THEN statement - only a subroutine or function.

Mike.

#### tumbleweed

##### Active Member
but trying to exit an IF THEN statement...
my objective is progress through a series of IF THEN statements and if the switch() is pressed then the code progress to the next IF THEN
You'll have to do a better job of describing how you want this to work. Use English. Don't use code to try and describe it since your coding is part of the problem.

"When the user presses a button I want the LED to come on and ..."

Loading