Lesson 5: Buttons
עמוד זה דורש דפדפן עדכני (תומך ב-SharedArrayBuffer). אנא עדכן את Chrome, Edge, Firefox או Safari לגרסה העדכנית ביותר.
English
Reading a pin
- A pin can also read:
digitalRead(2)givesHIGHorLOW. - The button on this board connects pin 2 to GND (0 volts) when you press it.
INPUT_PULLUPkeeps the pin HIGH when nobody presses. So: pressed = LOW.

void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);
}
void loop() {
if (digitalRead(2) == LOW) { // pressed
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
}
- Press Run, then hold the red button. The LED is on only while you press.
==asks "is it equal?". One=puts a value into a variable.
English
In the exam
- A button is an input device: it sends data into the computer. An LED is an output device.
- 0478/12/F/M/25 Q4(c): an ATM has a touch screen and a keypad (a grid of buttons). Give one other input device and one other output device to help people who cannot see. Mark scheme: input: a microphone or a Braille keypad; output: a speaker.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Turn it round: the LED on pin 13 is ON when nobody presses the button on pin 2, and OFF while you press it.
לחץ על הרץ כדי לראות את התוצא כאן.
רמת קושי 3/5 · 200 מטבעות + בונוס קטן בהשלמה הראשונה היום
Two buttons: pressing the button on pin 2 switches the LED on pin 13 ON. Pressing the button on pin 3 switches it OFF. The LED stays as it is when you let go.
לחץ על הרץ כדי לראות את התוצא כאן.