In SX Microcontrollers, SX/B Compiler and SX-Key Tool, John Kauffman wrote:
[3]
Can this code be more compact / more elegant?
[/3]
[3][/3]
[3]Below is some SX/B code that is very easy to understand; it flashes an LED if both switches are closed. [/3]
[3]Now I want to get it into as few lines (and as elegant) as possible. Any suggestions?[/3]
[3]Is there some way to do this with a variable sized bit instead of byte?[/3]
[3]Can I avoid the variable completely?[/3]
' code to flash MyLed when Switch1 AND Switch2 are closed
' Switch pins use internal pull-up so open = 1
' IO Pins
MyLed PIN RC.0
Switch1 pin RB.1
Switch2 pin RB.2
' Variables
SwitchTotal var byte
Main:
SwitchTotal = 0
SwitchTotal = SwitchTotal + Switch1
SwitchTotal = SwitchTotal + Switch2
IF SwitchTotal = 2 THEN
HIGH MyLed
Pause 500
HIGH MyLed
Pause 500
ENDIF
GOTO Main
---------- End of Message ----------
You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=157351
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)