Hi!
Haha, i am not planing count it by brain, it is just a part of a larger circuit. I am newbie with Arduino, so it turns the things difficult sometimes. I searched for it on Google but nothing i could find really helped. The code i used is here below. Very simple... But i think i am not in the correct way.
int input = 9; //Square Wave In
int ant = 0;
int cont = 0; // Counter
void setup() {
pinMode(input, INPUT_PULLUP); //It will count the zeros
Serial.begin(57600);
}
void loop() {
int reading = digitalRead(input);
if(reading != ant){
if(reading == LOW){
cont++;
Serial.print(cont);
}
}
ant = reading;
if(cont>=40){
cont=0;
delay(1000); // Stop to count for 1s before start it again.
}
}
It works but not with 40KHz, only until 5KHz, any idea?
The frequency is constant.