ATTiny, Counting with interupts

Robin2:
What is the purpose of all this? I've now seen your PM. I'm not going to deal with this privately but I won't make the PM public.

That's why I still posted a response here as well, this forum is to help people, like me, who are just getting started in the Arduino world. Hopefully others will learn from the code and answers from you helpful chaps.

My strong advice would be to develop your project with a second Arduino. The reason I'm suggesting 2 Arduinos is that you can program one of them to produce a stream of outputs that mimics the real world device you are trying to use. That way you can have a repeatable test.

I did think about this, but because the real world scenario is so random, I didn't think it would offer any advantage., especially now I have sorted out the reset part. I should have probably used a standard Arduino to make debugging easier and then switched to the ATTiny once it was up and running.

I think you need to spend a bit of time thinking about (and writing down) the exact specification of what you want to detect - all the cases that matter. You already have the fundamentals. You just need to build them into a complete project.

I have spent quite a bit of time thinking about it, but to be honest, I think the best thing to do, is get a prototype up and running and then go and test it in the real world.

It seems to me you want to reject some scenarios - such as one beep only within X msecs. And you want some minimum number of beeps to trigger a warning. And the more beeps the merrier. At the same time I don't think you can afford to have a dormant period because the valid train of beeps might start in that period. (Correct me if this is nonsense).

Pretty much sport on, initially I was just going to use a loop, reading the input pin, but this is such a waste of CPU/ battery life This is why I chose the interrupt route, as the device might sit for hours without any input, it seemed the logical way to approach the problem. (I still need to learn how to put the chip to sleep and then test if my pulses will wake it up, but I am hopeful this part will work)

Edit to add ... It will make your code much easier to understand if you move things out of loop() and into specific short functions. loop() should really have nothing but calls to the functions and, perhaps, a line to capture the latest value of millis().

I have already done that, as it was getting hard for me to follow my own code. I have also got the basic programming stuff working, with storing the values in Eeprom, everything just needs more testing and tuning. One obvious thing with my code, is that it is pretty much impossible to get a count of 1 with 250ms pulses.(The ISR sets the count to 1, and then 2 x 100ms reads make the count 3). Again this is not a problem as I just need to decide the upper and lower limits. I have also shortened the beep count time period to 1 second, as I don't want to really wait 3 seconds before deciding what to do.

Thanks again for all the help and advise so far.

Regards,

Les