Skip to content

Instantly share code, notes, and snippets.

@omsai
Created April 11, 2012 22:01
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save omsai/2363047 to your computer and use it in GitHub Desktop.
Save omsai/2363047 to your computer and use it in GitHub Desktop.
Arduino UNO pulse counter
/*
Arduino UNO reads rising edge trigger pulses on pin 2 and displays counter on
Sparkfun SerLCD LCD-10097
Photo of setup: http://ompldr.org/vZGNlbA/photo.JPG
Pariksheet <p.nanda@andor.com> Mar 2012
*/
#define LCD_REFRESH_INTERVAL_MS 100
/* Pin assignments */
#define INTERRUPT_INPUT 2
int pulse_counter = 0;
void setup()
{
Serial.begin(9600);
clear_LCD();
// For noise suppression, enable pullup on interrupt pin
digitalWrite(INTERRUPT_INPUT, HIGH);
attachInterrupt(INTERRUPT_INPUT - 2,
interrupt_handler,
RISING);
}
void loop()
// Keep LCD blank till a pulse comes in
if (pulse_counter > 0)
{
clear_LCD();
Serial.println(pulse_counter);
delay(LCD_REFRESH_INTERVAL_MS);
}
}
void clear_LCD()
{
Serial.write(0xFE);
Serial.write(0x01);
}
void interrupt_handler()
{
pulse_counter = pulse_counter + 1;
}
@escaleraalcielo
Copy link

After void loop() is there a "{" missing
void loop()
{
// Keep LCD blank till a pulse comes in
if (pulse_counter > 0)
{
clear_LCD();
Serial.println(pulse_counter);
delay(LCD_REFRESH_INTERVAL_MS);
}
}

@golddustcarl
Copy link

I know this is an old post, but no one has answered escaleraalcielo 's question. Yes, one is missing in front of the "if" statement. Left curly braces must equal right curly braces as the same as with parenthesis.

@khadijashamsi
Copy link

The URL of Photo of setup is not valid.
Do you have another URL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment