Hello,
I am having trouble getting the ArduinoLowPower LowPower.attachInterruptWakeup() method to work. Below is my code. Without the lowpower included the code works fine no problems at all. The interrupt is supposed to be set to wake up the board when the button on pin 9 is pressed. When press the button, nothing happens. Is this a code issue or an issue with the way my button is configured?
#include "ArduinoLowPower.h"
volatile int repetitions = 1;
int pos = 5;
const int bPin = 9;
const int ledPin = 2;
void repetitionsIncrease() {
repetitions ++;
}
void setup() {
Serial.begin(9600);
delay(1500);
pinMode(ledPin, OUTPUT);
pinMode(bPin, INPUT_PULLUP);
Serial.println("setup method");
LowPower.attachInterruptWakeup(bPin, repetitionsIncrease, CHANGE);
}
void loop() {
for (int i = 0; i < repetitions; i++) {
while (digitalRead(bPin) == HIGH && pos == 5) {
// blink LED on pin 2
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
Serial.println(pos);
pos = 110;
Serial.println(pos);
delay(500);
}
while (digitalRead(bPin) == HIGH && pos == 110){
// blink LED on pin 2
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println(pos);
pos = 5;
Serial.println(pos);
delay(500);
}
LowPower.sleep();
}
}