Go Down

Topic: 1 Piezo sensor and multiple Secret knocks? (Read 2333 times) previous topic - next topic

patduino

Hi FedxE,

I looked over the code and realized that it was pretty close to what you needed. For fun... I overachieved and gave you three knock patterns rather than the two you asked for.  I also left a few notes in the code to explain how to extend the pattern count to any number -- limited only by the amount of RAM in your Arduino.

At the end of the sketch is a function named validateKnock() that returns a bool indicating whether the knock pattern was accepted.  I modified that function to search through an array of potential knock patterns and to return an integer code indicating which pattern was found, or 0 if none.

I also added a few else-if statements to evaluate the returned value and to call the associated function and created a few placeholder functions for you to fill-in with your IFTTT GPIO calls.

NOTE - The code allows you to reprogram the secret knock code.  I did not extend this to work with more than just the first pattern in the list since there was only 1 programming button.  To reprogram all of them, you'll need to add additional buttons and modify the code to pay attention to which one was pressed.

Enjoy!

Pat.
There are 10 types of people in the world, those who understand binary, and those that don't.

FedxE

Hi FedxE,

I looked over the code and realized that it was pretty close to what you needed. For fun... I overachieved and gave you three knock patterns rather than the two you asked for.  I also left a few notes in the code to explain how to extend the pattern count to any number -- limited only by the amount of RAM in your Arduino.

At the end of the sketch is a function named validateKnock() that returns a bool indicating whether the knock pattern was accepted.  I modified that function to search through an array of potential knock patterns and to return an integer code indicating which pattern was found, or 0 if none.

I also added a few else-if statements to evaluate the returned value and to call the associated function and created a few placeholder functions for you to fill-in with your IFTTT GPIO calls.

NOTE - The code allows you to reprogram the secret knock code.  I did not extend this to work with more than just the first pattern in the list since there was only 1 programming button.  To reprogram all of them, you'll need to add additional buttons and modify the code to pay attention to which one was pressed.

Enjoy!

Pat.
Sir, YOU ARE THE BEST!!! it worked like a charm. Thank you so much. i will answer in PM too.

Go Up