-
-
Save JeffersGlass/4619128ef5bb9c6073b6d36d3ffe785c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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