Basic Reed switch ..

This commit is contained in:
Joe Tretter
2022-06-16 17:18:09 -05:00
commit 94353d2a4e
7 changed files with 149 additions and 0 deletions

24
src/main.cpp Normal file
View 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);
}