Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c11366e

Browse files
LED is on if the button pressed
1 parent 95b7971 commit c11366e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎Switch_Button/Switch_Button.ino‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const int buttonPin = 1; // the number of the pushbutton pin
2+
const int ledPin = 13; // the number of the LED pin
3+
4+
// variables will change:
5+
int buttonState = 0; // variable for reading the pushbutton status
6+
7+
void setup() {
8+
// initialize the LED pin as an output:
9+
pinMode(ledPin, OUTPUT);
10+
// initialize the pushbutton pin as an input:
11+
pinMode(buttonPin, INPUT);
12+
13+
Serial.begin(9600);
14+
}
15+
16+
void loop() {
17+
// read the state of the pushbutton value:
18+
buttonState = digitalRead(buttonPin);
19+
Serial.println(buttonState);
20+
21+
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
22+
if (buttonState == HIGH) {
23+
// turn LED on:
24+
digitalWrite(ledPin, HIGH);
25+
} else {
26+
// turn LED off:
27+
digitalWrite(ledPin, LOW);
28+
}
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /