LED Flashlight
Step 1 - Build the Project
Topics Covered:
To create an LED flashlight, you need to set up a button that 'holds its state', meaning it can clicked on and then clicked off.
Step 2 - Upload the Code
Step 3 - Read the Walkthrough
You'll first create a variable to hold the number of presses on the button. Then set up your LED and button in the setup().
The loop checks the state of the button. If it is pressed, the button will send a LOW signal and pressCount will increase by one with the ++ incrementor. A short delay ensures that one press isn't counted multiple times. Using an if statement, you create two scenarios.
Either the pressCount is 1 and the light is on, or else the light is off and pressCount is set equal to 0 again.