📜 ⬆️ ⬇️

Button and resistance

At least kill me, I do not understand why the button should be connected in this way:



Why it is impossible to connect the button in the same way as the LED - in series with the resistance? I tried. The effect is completely opposite. The simplest sketch “the button is pressed - the light is lit” acts exactly the opposite - while nothing is pressed, the LED is flickering (and does not light up!). You press the button - the diode goes out.
')
  #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);
 } 

Source: https://habr.com/ru/post/83381/


All Articles