Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Last active July 6, 2020 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffersGlass/4619128ef5bb9c6073b6d36d3ffe785c to your computer and use it in GitHub Desktop.
Save JeffersGlass/4619128ef5bb9c6073b6d36d3ffe785c to your computer and use it in GitHub Desktop.
const int buttonPin = 2;
const int NUM_READINGS = 9;
volatile int myReadings[] = {0,0,0,0,0,0,0,0,0};
const int TRIGGER_COUNT = 5;
void setup() {
// put your setup code here, to run once:
Serial.begin(38400);
pinMode(buttonPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), getReadings, FALLING);
}
void loop() {
delay(1000);
int count = 0;
noInterrupts(); //cli();
for (int i = 0; i < NUM_READINGS; i++){
if (myReadings[i] > 0) count++;
}
interrupts(); //sei()
if (count > TRIGGER_COUNT) Serial.println("Trigger is Go!");
else Serial.println("Not enough to trigger.");
}
void getReadings(){
for (int i = 0; i < NUM_READINGS; i++){
myReadings[i] = digitalRead(i+4);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment