I want to count rising and falling pulse within a time set by another pulse.I am not much familiar with arduino coding so it will be helpful if meaning of code is written with that.
the code i used is too simple and it's actually not counting rising and falling but whenever input is high counts are increasing although by adding delay of almost same of pulsewidth can get rid of redundent counting but i guess it's not a good idea. please someone suggest me how to count only rising and falling edge. Thanks in Advance
Here is code i have used
const int inputPin = A3;
const int currentPin = A1;
const int input = 3;
unsigned int COUNT = 0;
unsigned int voltage = 0;
unsigned int current = 0;
volatile byte state = LOW;
void setup() {
Serial.begin (9600);
pinMode(input, INPUT);
}
void loop() {
repeat: voltage = digitalRead(input);
if(voltage>0)
{
COUNT = COUNT+1;
delayMicroseconds(500);
}
else {
COUNT = COUNT;
}
current = analogRead(currentPin);
if(current > 900)
{
Serial.println(COUNT);
delay(1000);
COUNT = 0;
}
else {
goto repeat;
}
}