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

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    [​IMG]
     
    • Like Like x 1
  2. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    curious question?? a steeper motor instead of an anglouge type gauge using a coil and a needle for pointer?
     
  3. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,629
    Likes:
    145
    Location:
    Seattle, WA
  4. dave miyares

    Dave New Member

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

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    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??
     
  6. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,629
    Likes:
    145
    Location:
    Seattle, WA
    Probably not. They are designed to move a pointer weighing vitually norhing over a amall arc.
     
  7. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,629
    Likes:
    145
    Location:
    Seattle, WA
    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).

    SmartSelectImage_2018-02-06-09-04-16.png SmartSelectImage_2018-02-06-09-04-16.png
     
  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
    LOTS of interesting info
    Thanks. Will start reading as soon as I get done with kitchen project for my wife.
     
  10. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    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
     
  11. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    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.
     
  12. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    5,198
    Likes:
    159
    Location:
    morristown,tn
    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: Feb 17, 2018
  13. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    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.
     
  14. tumbleweed

    tumbleweed Active Member

    Joined:
    Jan 25, 2007
    Messages:
    133
    Likes:
    36
    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 (text):

    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
     
     
  15. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,629
    Likes:
    145
    Location:
    Seattle, WA
    What's with the indecipherable mess that's supposed to be code?
     
  16. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    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.
     
  17. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,629
    Likes:
    145
    Location:
    Seattle, WA
    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?
     
  18. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    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.
     
  19. MrDEB

    MrDEB Well-Known Member

    Joined:
    Apr 16, 2007
    Messages:
    4,592
    Likes:
    25
    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??
     
  20. JonSea

    JonSea Well-Known Member

    Joined:
    Oct 1, 2012
    Messages:
    1,629
    Likes:
    145
    Location:
    Seattle, WA
    If blah = blah Then
    Exit
    End If

    From the Swordfish doc:

    SmartSelectImage_2018-02-19-21-07-45.png
     
  21. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,710
    Likes:
    421
    Location:
    Brisbane Australia
    ONLINE
    You cannot EXIT an IF THEN statement - only a subroutine or function.

    Mike.
     
  22. tumbleweed

    tumbleweed Active Member

    Joined:
    Jan 25, 2007
    Messages:
    133
    Likes:
    36
    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 ..."
     

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