Hey
I have been pointed in the direction of this Fourm as I have been told you are good at giving advice
I am looking at making an Led Circuit to go on a Nerf blaster
The idea is that when you press one button a strip of 6 LEDs will light up, then when you pull the trigger one led will turn off until non are left
Hope this is something you can advise on
Many thanks
James
Tell me if Iām getting this correct.
So youāre looking for something that has a āReloadā button which lights up all the LEDās, and then upon each trigger pull, to turn one LED at a time. Kinda of like an ammunition indicator?
Also, whatās your level of electronics experience?
Yes yes this is correct and it is very minimal but iām am willing to learn.
Sorry I have taken so long to reply i have been away on placement.
James
I assume the trigger is nothing more than a switch / button.
6 LEDS on pins 2 to 7 (see circuit #4 in the SIK guide as example)
Buttons (buttons and trigger cord) on pins 8 and 9 (see circuit #5 in the SIK guide as example; just move the wires to other pins.)
I did not look at the example code, but Iām quite sure that mixing and matching with some modifications can get you there.
If button 1 (start) is pressed, switch on all LEDs.
Keep a global variable that counts the number of times that the trigger is pulled.
If button 2 (trigger) is pressed, read the counter, switch off the correct LED and increment the counter. When all LEDs are off, (re)set the counter to 0.
Note that you probably need to debounce the trigger. You can do that in hardware or in software. Software debouncing can (in itās simplest form) be achieve with the delay function (try delay(50) or delay(100) depending on the results).
Debouncing is required because the behaviour of buttons as shown below
CLOSED (ON) +--+ +--+ +--+ +--+ +-----------------------------+
| | | | | | | | | switch is stable |
OPEN (OFF) --+ +--+ +--+ +--+ +--+ +----------
^ ^
| |
press release
If you donāt debounce, the microcontroller is fast enough to count 5 āpressesā.
If you need help with code, show what you tried, describe the problem and we will try to help further.