Shop OBEX P1 Docs P2 Docs Learn Events
Useing keyboard to ajust varubles?? — Parallax Forums

Useing keyboard to ajust varubles??

krazyideaskrazyideas Posts: 119
edited 2008-10-02 02:26 in Propeller 1
I have the propeller Demo board along with the assesorites kit which has a key board.
I want to use the keys on the key board to modifi my program on the fly useing a Dat and an if (this key is pressed) then adjust this varuble this much.
I have the keyboard program that alows me to type on screen but how do I make it affect my varubles

And if ya didn't guess I'm just starting out with this and I'm just learning, so lamans terms would be great.
Thanks so much

crazyideas

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-22 23:45
    Do you want to have volume like control (increase/decrease) or be able to enter an arbitrary number?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • BTXBTX Posts: 674
    edited 2008-09-23 00:33
    Sorry for OT, but....
    Paul and crazyideas, let me know if you need Spanish assistant.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-23 01:48
    You need to modify your keyboard routine so it checks for specific characters and changes your variable like:
    ' Here the new input character is in the variable called K
       ' This code is in a REPEAT loop after reading a key from the keyboard
       IF K == "+"
          myValue := myValue + 1
       ELSEIF K == "-"
          myValue := myValue - 1
       ELSE
          ' It's not a key that's recognised
          ' You could display an error message
          ' or just ignore the key
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-23 03:24
    Another option when you have several different variables is to use a letter to specify which variable you want to control.
    If you store 12 variables in an array, you could use the letters "a" through "l" for the 12 variables. The next "+" or "-"
    would affect the last variable you specified. The default variable would be "a".
    ' Here are the variables and the pointer to the current one
    VAR long variables[noparse][[/noparse]12], varNumber
    
    ' Here (in your initialization routine) you set up the default
       varNumber := 0
    
    ' Here is the stuff in the REPEAT loop for reading keys
       IF K => "a" AND K =< "l"
          varNumber := K - "a"
       ELSEIF K == "+"
          variables[noparse][[/noparse]varNumber]++
       ELSEIF K == "-"
          variables[noparse][[/noparse]varNumber]--
       ELSE
          ' Something else
    
  • krazyideaskrazyideas Posts: 119
    edited 2008-09-30 20:02
    Ok well I still can't make it work.·

    I searched all through the manuel that I have and I couldn't really understand what I was doing, or where to put it. Programing the propellor is alot different then the basic stamp.


    This is what Mike gave to me. When I read it I thought Oh that won't be too hard, but then it was. I know that it has to be easy but I'm so new at this that it is hard. So I need some more clarification.
    Thanks to anyone that sends some helpful info.


    Another option when you have several different variables is to use a letter to specify which variable you want to control.
    If you store 12 variables in an array, you could use the letters "a" through "l" for the 12 variables. The next "+" or "-"
    would affect the last variable you specified. The default variable would be "a".

    '·Here·are·the·variables·and·the·pointer·to·the·current·one
    VAR·long·variables[noparse][[/noparse]12],·varNumber

    '·Here·(in·your·initialization·routine)·you·set·up·the·default
    ···varNumber·:=·0

    '·Here·is·the·stuff·in·the·REPEAT·loop·for·reading·keys
    ···IF·K·=>·"a"·AND·K·=<·"l"
    ······varNumber·:=·K·-·"a"
    ···ELSEIF·K·==·"+"
    ······variables[noparse][[/noparse]varNumber]++
    ···ELSEIF·K·==·"-"
    ······variables[noparse][[/noparse]varNumber]--
    ···ELSE
    ······'·Something·else
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-30 20:08
    It really helps if you indicate what you do understand and what you don't understand. If you don't understand any of it, then you need to go back to the beginning and perhaps work through the Propeller Education Kit tutorials until you've got a better handle on the basics.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-30 20:18
    If you find difficulties with code, the easiest thing to do is simplify the code down to the bare essentials. For instance look for a particular key and toggle an LED every time you see the key pressed. Then build the complexity gradually making sure it works at every step.

    I hope you weren't thinking Mike's code was an all encompassing example, it doesn't even fetch any keystrokes. So it's not going to work unless you dress it up into functional code.

    If you want an example of the absolute simplest keyboard interfacing, look at Keyboard_Demo.spin in your Examples/library. If you want to look at more complex keyboard interfacing look at the logic analyzer application I wrote: http://forums.parallax.com/showthread.php?p=606048

    The repeat loop (first line in repeat loop is keyok := false) in Start_DScope, incrementing and decrementing (along with boundry checking) is done when processing the up and down arrows. This is identical to what you are trying to do. The keyboard handling in Set_Preferences is an even more complex example of editable hexidecimal data entry.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 9/30/2008 8:24:31 PM GMT
  • krazyideaskrazyideas Posts: 119
    edited 2008-09-30 21:25
    Ok thanks guys.
    I will try and work through the manuel again.
  • rjo_rjo_ Posts: 1,825
    edited 2008-10-02 02:26
    krazyideas,

    You almost have it... where you are having trouble is with the (varNumber := K - "a") statement.


    You need a lookdown instruction ... and then just store the key values in an array. page 242 in the Propeller User Manual.

    Rich
Sign In or Register to comment.