raspberrypi:wiringpi:event_count
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 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.txt · Last modified: by aistis
