Skip to content

Instantly share code, notes, and snippets.

@stevenpetryk
Last active August 29, 2015 13:57
Show Gist options
  • Save stevenpetryk/9612326 to your computer and use it in GitHub Desktop.
Save stevenpetryk/9612326 to your computer and use it in GitHub Desktop.
#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