In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote: As Been points out there is nothing at all wrong with you code. If, however, you find yourself pressed for space at some point you can reduce the code used using "fancy stuff with bit masks." It is not as easy to read as your verbose code, but it does use a lot less space. Here's the Main section: [code]Main: tmpBtns = GET_BTNS IF tmpBtns = %00000000 THEN Main FOR idx = 0 TO 5 mask = 1 << idx ' create mask for input check = tmpBtns & mask ' test the button IF check > 0 THEN Leds = mask CNG_PGM idx ' change selected program DO tmpBtns = GET_BTNS LOOP UNTIL tmpBtns = %00000000 ' force release GOTO Main ENDIF NEXT GOTO Main[/code] As you can see, this calls a function called GET_BTNS which handles the input debouncing: [code]GET_BTNS FUNC 1, 0, 0[/code] [code]FUNC GET_BTNS gbIdx VAR tmpB1 gbResult VAR tmpB2 gbReseult = %00111111 ' assume pressed FOR gbIdx = 1 TO 25 ' 25ms debounce DELAY_MS 1 gbResult = gbResult & RB ' scan inputs NEXT RETURN gbResult ENDFUNC[/code] Once you get your project working save a new version and try this to see how you like it. Even if you don't use it here, masking tricks are handy to have up one's sleeve. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=394524#m395017 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)