Basic Reed switch ..
This commit is contained in:
24
src/main.cpp
Normal file
24
src/main.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user