Code: Select all
===========================================
// This is the Interrupt test, using LED output of ItsyBitsy.
// Make sure "Get board info" shows: "Adafruit ItsyBitsy nRF52840 Express"
#include <bluefruit.h>
// AdaFruit board numbers for pins to be grounded momentarily by switches
// There is an external pullup resistor on each pin.
int pin0 = 13;
int pin1 = 12;
int pin2 = 11;
int pin3 = 10;
int pin4 = 9;
int pin5 = 7;
int pin6 = A2;
int pin7 = A4;
unsigned long Act = 0;
volatile unsigned char ksw;
void flash(byte times, unsigned long on, unsigned long off) {
while (times > 0) {
digitalWrite(LED_BUILTIN, HIGH);
delay(on);
digitalWrite(LED_BUILTIN, LOW);
delay(off);
times--;
}
delay(5000);
}
// Interrupt Service Routines
void Cntc_0() {ksw = 0;}
void Cntc_1() {ksw = 1;}
void Cntc_2() {ksw = 2;}
void Cntc_3() {ksw = 3;}
void Cntc_4() {ksw = 4;}
void Cntc_5() {ksw = 5;}
void Cntc_6() {ksw = 6;}
void Cntc_7() {ksw = 7;}
void setup(void) {
pinMode(pin0, INPUT);
pinMode(pin1, INPUT);
pinMode(pin2, INPUT);
pinMode(pin3, INPUT);
pinMode(pin4, INPUT);
pinMode(pin5, INPUT);
pinMode(pin6, INPUT);
pinMode(pin7, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
attachInterrupt(digitalPinToInterrupt(13),Cntc_0,LOW);
attachInterrupt(digitalPinToInterrupt(12),Cntc_1,LOW);
attachInterrupt(digitalPinToInterrupt(11),Cntc_2,LOW);
attachInterrupt(digitalPinToInterrupt(10),Cntc_3,LOW);
attachInterrupt(digitalPinToInterrupt(9), Cntc_4,LOW);
attachInterrupt(digitalPinToInterrupt(7), Cntc_5,LOW);
attachInterrupt(digitalPinToInterrupt(A2),Cntc_6,LOW);
attachInterrupt(digitalPinToInterrupt(A4),Cntc_7,LOW);
Act = 0;
ksw = 8;
}
void loop() {
if(++Act > 1000) {
Act = 0;
flash(3,200,200);
}
if(ksw != 8) { // an intrrupted happened
ksw = 8;
Act = 0;
flash(5,5000,5000);
}
}