Button
Turns on and off a LED, when pressing button attach to pin 7
hardware
- Arduino Board
- Button Board
wire
- SIG 7
- VCC S
- GND -
code
const int keyPin = 7;
const int ledPin = 13;
void setup() {
// put your setup code here, to run once:
pinMode(keyPin, INPUT); // Initialize the key pin as input
pinMode(ledPin, OUTPUT); // initialize the led pin as output
}
void loop() {
// put your main code here, to run repeatedly:
boolean Value = digitalRead(keyPin); // read the state of the key value
// and check if the key is pressed
// if it is, the state is HIGH
if (Value == HIGH) {
digitalWrite(ledPin, LOW); // turn on the led
} else {
digitalWrite(ledPin, HIGH); // turn off the led
}
}