Newbie LED lightup sequence help

Hi all,

I’m fairly new to Arduinos but have been spending the last few weeks reading countless articles and watching a number of videos online about them in an effort to work out whether I can achieve the following.

Basically the idea is to come up with a way of turning on a maximum of 10 LEDs one at a time by a single momentary push switch but there are several caveats:

  1. The first 9 LEDs need to have a toggle switch connected to each one but the last LED does not need one – the idea is at least one of the LEDs will turn on.

  2. When the momentary switch is pressed for the first time the first LED should turn on but only if the toggle switch connected to it is on.

  3. If the toggle switch for the first LED is off then the programme should move on to the next LED in the sequence and apply the same logic.

  4. If the toggle switch is on then the LED connected to it should turn on. The programme should then wait for the next time the momentary switch is pressed.

  5. When the momentary switch is next pressed it should identify the last LED that was turned on and check the next LED in the sequence in the same way as described in point 3.

  6. After the tenth and last LED is turned on there should be a short delay where all the activated LEDs then turn off. This would be the end of the programme.

Where I’ve said above about the toggle switches it will usually be the first few in the sequence that may be off and the rest will be on, there will never be a situation where the switches are alternately on and off, two on and next two off etc.

Hopefully this makes sense; I haven’t acquired an Arduino yet as I wanted to be sure this was entirely within the realms of possibility in setting up beforehand before committing myself. Having said that though I have many other things besides the above that I would like to try out so I will likely get one anyway.

Many thanks in advance.

Alan

LEDs need to have a toggle switch connected to each one

Do you mean the toggle switch is literally connected to the led, or just associated with the led?

The two components should be connected in series with each other, and if that means the LED connects directly with the toggle switch then yes.

Ok, so my next question is why they would be connected?

I ask because I am trying to help you by imaging how the the led, series resistor, switch and Arduino pin would be connected, such that the switch and Arduino can both control the led, and the Arduino can read the position of the switch. If the switch and led were connected to separate Arduino pins, then it is easy (but 2x Arduino pins needed).

Ok, I think this will work:

The led can only be lit if the switch is in the up position. The Arduino output will need to be OUTPUT & LOW for the led to be lit. If the swich is in the down position, the led cannot be lit by the Arduino, but using INPUT mode, the Arduino will be able to read which position the switch is in. It will read LOW if the switch is in the down position and HIGH when the switch is up.