Shop OBEX P1 Docs P2 Docs Learn Events
How to let propeller chip distinguish what I have already input though a keyboard? — Parallax Forums

How to let propeller chip distinguish what I have already input though a keyboard?

daniel dingdaniel ding Posts: 52
edited 2011-11-12 04:53 in Propeller 1
[FONT= ]Hi everyone
I have use a lcd.out(key.newkey) command to display the keyboard input. now I want to let the propeller distinguish what the lcd is displaying.
For one, if I press the "g" key on keyboard and lcd display a "g" charactor, and the chip know taht I input a "g" charactor ,and if I press enter key next the chip will light a led.
more I want to add a number after charactor "g" to decide the frequency of the led light.
thanks
daniel[/FONT]

Comments

  • SRLMSRLM Posts: 5,045
    edited 2011-11-11 19:44
    You'll need to capture the keyboard input key in a variable, then test it to determine what to do. Something like this (untested psuedo-ish code)
    VAR
    	byte key_input
    	
    PUB Main
    	repeat
    		key_input := key.newkey
    		if(key_input == 'g')
    			--do something
    		else if(key_input == '/n')
    			--do something else
    			--aka, wait for the key following:
    			key_input := key.newkey
    			if(key_input == '1')
    				--do something
    			else
    				--do something else
    		else
    			--it's not something special, so display it
    			lcd.out(key_input)
    

    If you have lots of different conditions and sequences you may want to draw out a state machine for your tasks and code that up instead.
  • daniel dingdaniel ding Posts: 52
    edited 2011-11-11 22:44
    SRLM
    thanks for ur reply, but you know the"key.newkey" is a number of ASCII.
    the command of you gave key_input=="g"????
    also need a display of "g" the same time do something
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-11-12 04:53
    ASCII is simply a definition of which byte should corrospond to which character. If you have a keyboard that creates ASCII numbers for each key .. or if you have an LCD which accepts ASCII numbers ... or a terminal program ..... or a compiler which compiles strings to ASCII arrays ... in all these cases you have no problem taking a character on one hand and directly output it to the other hand.
    In your example you can directly take the keyboard-input and send it to the LCD.
    And as the propeller tool also creates ASCII-characters (at least for the number range defined by ASCII) you can also compare the keyboard-input with the single character in the code:
    key_input == 'g'
    And it will be true if you entered a g and id will be false if you entered something else.

    To output the entered key you simply add:
    key_input := key.newkey
    lcd.out( key_input )
    ...

    The point is that you have to store the key input somewhere if you want to do 2 things with it. In your example from the begining you send the key.newkey directly to the lcd and then it's gone. Now way to check the content afterwards - except reading it back from LCD, which is a lot of overhead.
Sign In or Register to comment.