Last active
August 29, 2015 13:57
-
-
Save stevenpetryk/9612326 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
#define sampleRate 1 | |
#define progChangeDuration 1000 | |
#define threshold 20 | |
void setup() | |
{ | |
pinMode(2, INPUT); | |
} | |
void loop() | |
{ | |
int rf_input = analogRead(1); | |
if (rf_input > threshold) | |
if(detectHigh()) { | |
// send something to serial, then delay or whatever | |
} | |
} | |
bool detectHigh() | |
{ | |
int time = progChangeDuration; | |
int count = 0; | |
while(time-->0) { | |
if(analogRead(1) > threshold) | |
count++; | |
delay(sampleRate); | |
} | |
int totalCycles = progChangeDuration / sampleRate; | |
int expectedHighCount = totalCycles/2; | |
if(abs(count-expectedHighCount) < 40) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment