In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote: Glad it worked. Looking at it again this morning I found that there are unnecessary IF-THENs; here's a more efficient version of the Main loop: [code]Main: RANDOM seed ' stir random value myButtons = GET_BUTTONS ' 50ms delay IF myButtons = %0000 THEN ' default Leds = %0001_0000 ' Led1 only GOTO Main ENDIF IF myButtons.3 = IsOn THEN Led1 = seed.7 Led2 = seed.3 Led3 = seed.1 Led4 = seed.5 DELAY_MS 100 GOTO Main ENDIF Led1 = IsOff Led2 = myButtons.0 Led3 = myButtons.1 Led4 = myButtons.2 GOTO Main[/code] The only special cases are no buttons or the fourth button -- after than you're simply moving the button status to an LED so this version is cleaner. You could actually reduce the final section to these two lines: [code]Leds = myButtons << 5 Led1 = IsOff[/code] ...but this is not as easy to understand. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=313149#m315147 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)