cmcc60,
There are at least a half-dozen different ways to do what you are trying to do. The simplest one that comes to mind is as follows...
Code:
+-----------------+
| UP/DOWN COUNTER |
PB1 | |
----| |--------+ Up |
PB2 | |
----| |--------+ Down |
PB3 | |
----| |--------+ Reset |
| |
+-----------------+
CNT
---| = |--------------------( LT-1 )
1
CNT
---| = |--------------------( LT-2 )
2
CNT
---| = |--------------------( LT-3 )
3
ETC.
Everytime you push PB1 the count increments. Only the count-specified light goes ON; 1, 2, 3,... etc. All others are OFF.
Everytime you push PB2 the count decrements; ...3, 2, 1, 0.
When you push PB3 the counter is reset to zero and all lights go OFF.
You would probably have to build a "de-bouncer" to keep your counter from mis-counting.
There are also methods using Adders, Shift Registers, Pointers...
There is another method which decides which light to turn ON based on which light is currently ON...
...if 5, then 6, NOT 5
...if 6, then 7, NOT 6
...if 7, then 8, NOT 7
This one is a little tricky in that the pseudo-code should really look like this...
...if 7, then 8, NOT 7
...if 6, then 7, NOT 6
...if 5, then 6, NOT 5
The examinations proceed backward from 16 to 1 rather than from 1 to 16. Can you understand why this is necessary in this particular code?
The whole point of this exercise, regardless of the method you use, is to figure out how to trap (detect) the OFF-to-ON transition and make it work for you. Can you see why simply looking to see if the PB is ON is problematical?