Hi,
I am counting 5 V pulses, 1 to 10 pulses per second, varying length and spacing, in Uno R3 per page 682 of the Arduino Cookbook:
const int hardwareCounter=5 //input pin fixed to integral timer
void setup()
{
pinMode(buttonOn, INPUT_PULLUP);
TCCR1A=0;
}
void loop()
{
//Start the counting
bitSet(TCCR1B, CS12);//Counter clock source is external pin 5
bitSet(TCCR1B, CS11; //Clock on rising edge
delay(samplePeriod); // Sample period set to (4000), 4 seconds
TCCR1B=0; //Stop the counting
count=TCNT1; //Counter output
TCNT1=0; Reset the hardware counter
The counter output is then used in my logic as follows:
if((b=!digitalRead(buttonOn)||count>4))
{
etc.
This works perfectly in the Uno R3, which I happened to "fry" and ordered an R4...
Can anyone help with doing this in the R4? Thanks