I am working on an arduino project that involves some basic circuits and LED's.
I have one basic circuit that goes from pin 3 (which is set to high), to a pushbutton, and into pin 4. What happens next will be determined (with an "if" statement) by whether pin 4 receives current (by the button being pushed) or not.
I have tried both google and youtube and could not find anything that would help.
What code would I use to determine if current is flowing into pin 4?
What code would I use to determine if current is flowing into pin 4?
digitalRead() will tell you whether the voltage on the pin is above the threshold to be considered HIGH, or not. Nothing on the Arduino measure current.
If current is flowing into the pin, then your Arduino is probably broken.
And your scheme for connected one pin to another via a push-button is conceptually flawed. If the purpose is to detect whether the button has been pressed, it won't work.
Now the L LED will follow the output of pin 3 high or low using pin 4 as an input.
Same thing can be done using a push button to Gnd on pin 4 instead of the output of pin 3. The weak internal pullup resistor (20K to 50K) on pin 4 will hold it high until something takes pin 4 low.
If pin 3 is an output, then when pin3 is connected to pin 4 (via a jumper, or via a push button), pin 4 will go high & low following pin 3 whether pin 4 has its pullup turned on or not. The pullup will make pin 4 go to a known state when pin 3 is disconnected, and not float high & low yielding random results.
Writing a 1 to a bit in the PIN register will TOGGLE the associated bit in the PORT register - the zeros will have no effect on the rest of the bits in the PORT register.