プログラム
button_monitor.ino
// ---------------------------------------------------------------------
// button_monitor.ino
//
// Feb/04/2023
// ---------------------------------------------------------------------
#define PROGRAM "button_monitor.ino"
#define VERSION "2023-2-4 AM 10:30"
const int buttonPin = 15; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0;
int buttonState_before = 0;
// ---------------------------------------------------------------------
void setup()
{
Serial.begin(115200);
delay(3000);
Serial.println(PROGRAM);
Serial.println(VERSION);
Serial.println();
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
// ---------------------------------------------------------------------
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
if (buttonState_before != buttonState)
{
Serial.println(buttonState);
Serial.println(PROGRAM);
Serial.println(VERSION);
Serial.println();
buttonState_before = buttonState;
}
}
// ---------------------------------------------------------------------