Button and resistance
Although I’ll kill you, I don’t understand why the button needs to be connected in this way:
Why can not I connect the button in the same way as the LED - in series with the resistance? I tried it. The effect is completely opposite. The simplest sketch “the button is pressed - the lamp is lit” acts exactly the opposite - until nothing is pressed, the LED flickers (and does not light up evenly!). Press the button - the diode goes off.
Why can not I connect the button in the same way as the LED - in series with the resistance? I tried it. The effect is completely opposite. The simplest sketch “the button is pressed - the lamp is lit” acts exactly the opposite - until nothing is pressed, the LED flickers (and does not light up evenly!). Press the button - the diode goes off.
#define BUTTON 7 #define LED 12 int btnState; int btnPrevState; void setup () { pinMode (LED, OUTPUT); pinMode (BUTTON, INPUT); } void loop () { btnState = digitalRead (BUTTON); if (btnState == HIGH) { digitalWrite (LED, HIGH); } else { digitalWrite (LED, LOW); } delay (10); }