I am trying to write a code to take an analog input and control a digital output. I have successfully done this. In my code when A3 drops below 4.7 volts it ties my digital pin high. Its simple and the digital pin corresponds directly to the analog "pulse" I say pulse because the analog input is getting a 5v signal from the lock system on my car.
My question is how would I make 3 pulses into A3 trigger a digital pin? So 3 pulses dropping the input below 4.7V (which my car circuit does) will trigger the output.
Second how could I do this within a couple seconds? So it would take a quick blast of 3 pulses then trigger an output. When it senses the 1st analog drop it needs to see the next 2 within or couple seconds or the whole thing "resets" waiting for that first pulse again.
You start with your original program. Then when you see the first pulse you make a note of the current time with the millis() function. Then set a count variable to one.
then look for the pulse again and if you see one increment the variable again.
Each time round the loop you check if the current time given by millis() is 2 seconds on from the time of the first pulse.
If it is you reset the counter.
When your counter reaches three without being reset then you have your event.
Please upload photos and code it would be appreciatted ! You can share them with with DropBox for more arduino compatibility
To use 3 analog inputs :
I guess the port A1 A2 A3 are free ?
Why not use them to attach a wire to it ?
To trigger a timer during one second after your first analog input A0 is high I would use this code :
if (Analog0==HIGH){
int timeWhenA0Activated = millis();
while( millis()< timeWhenA0Activated + 1000){ //do code 1 second after Analog 0 was high
print.lcd("Thanks Masterleo I 'll give you some karma") //do this
}
}