raspberrypi:wiringpi:event_count
This is an old revision of the document!
Susiskaičiuoja kiek kartų įvykis atsitiko per sekundę
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>
#define BUTTON_PIN 2 // Use GPIO Pin 17
volatile int eventCounter = 0; // the event counter
// -------------------------------------------------------------------------
// myInterrupt: called every time an event occurs
void myInterrupt(void) {
eventCounter++;
}
// -------------------------------------------------------------------------
int main(void) {
// sets up the wiringPi library
if (wiringPiSetupGpio () < 0) {
fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));
return 1;
}
// set Pin generate an interrupt on high-to-low transitions
// and attach myInterrupt() to the interrupt
if ( wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0 ) {
fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
return 1;
}
// display counter value every second.
while ( 1 ) {
printf( "%d\n", eventCounter );
eventCounter = 0;
delay( 1000 ); // wait 1 second
}
return 0;
}
raspberrypi/wiringpi/event_count.1485895311.txt.gz · Last modified: by aistis
