User manual
and activate the internal pull-up-resistance, by
ing
digitalWrite()
to write a 1 for HIGH on the input. Now a voltage
of approx. 5 V is pending at the input in the resting condition.
Now you can pull the input against GND (ground) with the button.
This pull-up-resistance is integrated in the microcontroller and
has a value of approx. 20 to 50 kΩ. Regarding function, it is
the same as if applying an external resistor from input D7 to
+5 V. In the resting condition, the program will therefore always
recognise a HIGH at input D7 and a LOW when the button is pushed.
Therefore, the button query is applied with a question mark in
the program. This is called the NOT-operator in C-programming.
Since it is known that an If()-query checks for TRUE , everything
else will be interpreted as FALSE . If the If()-query has been
performed without this operator, the condition would always be
TRUE. It would then already be performed before the button had
even been pushed. The NOT-operator inverts the status of the
button. 1 turns into 0 and 0 turns into 1 and the If()-query is
now only TRUE if the button has actually been pushed.
Example code: LOTTERY
001 // Integrating LCD-Library
002 #include <LiquidCrystal.h>
003
004 // Specifying LCD pins
005 // RS, E, D4, D5, D6, D7
006 LiquidCrystal lcd(11, 10, 2, 3, 4, 5);
007
008 #define Backlight 9
009 #define button 7
010
011 int i, zahl=0;
012 int Anz = 6;
013
014 void setup()
015 {
016 analogWrite(Backlight, 200);
017
018 pinMode(button, INPUT);
019 digitalWrite(button, HIGH);
020
021 lcd.begin(16, 2);
022 lcd.setCursor(0, 0);
023 lcd.print("LOTTO 6 of 49");
024 delay(1000);
025 lcd.clear();
026
027 randomSeed(analogRead(0)*5);