From 07e1e3a3a3a4842d23256380da8344b815f0776f Mon Sep 17 00:00:00 2001 From: Dean Smith Date: Wed, 22 Jan 2020 20:40:01 +0000 Subject: [PATCH] Testing bike switch --- IntTest/IntTest.ino | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 IntTest/IntTest.ino diff --git a/IntTest/IntTest.ino b/IntTest/IntTest.ino new file mode 100644 index 0000000..db5472f --- /dev/null +++ b/IntTest/IntTest.ino @@ -0,0 +1,35 @@ +const int buttonPin = 2; // the number of the pushbutton pin +const int ledPin = 3; // the number of the LED pin +char msg[256]; + +// variables will change: +volatile int buttonState = 0; // variable for reading the pushbutton status + +void setup() { + + Serial.begin(9600); + while (!Serial); + + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); + // initialize the pushbutton pin as an input: + pinMode(buttonPin, INPUT); + // Attach an interrupt to the ISR vector + attachInterrupt(digitalPinToInterrupt(2), pin_ISR, CHANGE); + Serial.println("Setup"); +} + +void loop() { + // Nothing here! +} + +void pin_ISR() { + sprintf(msg,"INT @ %lu", millis()); + Serial.println(msg); + buttonState = digitalRead(buttonPin); + if (buttonState) { + Serial.println("Closed"); + } else { + Serial.println("Open"); + } +}