24 lines
543 B
C++
24 lines
543 B
C++
|
|
#include <Arduino.h>
|
||
|
|
|
||
|
|
const int buttonPin = 4; // Reed switch - don't forget the pull down resistor.
|
||
|
|
const int ledPin = 2; // Internal LED
|
||
|
|
|
||
|
|
void setup() {
|
||
|
|
Serial.begin(9600);
|
||
|
|
// initialize the pushbutton pin as an input
|
||
|
|
pinMode(buttonPin, INPUT);
|
||
|
|
// initialize the LED pin as an output
|
||
|
|
pinMode(ledPin, OUTPUT);
|
||
|
|
}
|
||
|
|
|
||
|
|
void loop() {
|
||
|
|
int buttonState = digitalRead(buttonPin);
|
||
|
|
Serial.println(buttonState);
|
||
|
|
|
||
|
|
if (buttonState == HIGH) {
|
||
|
|
digitalWrite(ledPin, HIGH);
|
||
|
|
} else {
|
||
|
|
digitalWrite(ledPin, LOW);
|
||
|
|
}
|
||
|
|
delay(500);
|
||
|
|
}
|