반응형
라즈베리파이 GPIO 포트를 인터럽트로 사용하는 예제소스코드입니다. 참고하십시요. 출처 주석안에 표시되어 있습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | /* D. Thiebaut based on isr.c from the WiringPi library, authored by Gordon Henderson https://github.com/WiringPi/WiringPi/blob/master/examples/isr.c Compile as follows: gcc -o isr4pi isr4pi.c -lwiringPi Run as follows: sudo ./isr4pi */ #include <stdio.h> #include <string.h> #include <errno.h> #include <stdlib.h> #include <wiringPi.h> // Use GPIO Pin 17, which is Pin 0 for wiringPi library #define BUTTON_PIN 0 // the event counter volatile int eventCounter = 0; // ------------------------------------------------------------------------- // myInterrupt: called every time an event occurs void myInterrupt(void) { eventCounter++; } // ------------------------------------------------------------------------- // main int main(void) { // sets up the wiringPi library if (wiringPiSetup () < 0) { fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno)); return 1; } // set Pin 17/0 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; } | cs |
반응형
'라즈베리파이' 카테고리의 다른 글
Python development library를 설치 (0) | 2019.02.21 |
---|---|
apache2 리스타트 에러 - Job for apache2.service failed. (0) | 2019.02.21 |
온도 습도 센서 DHT11 에러. raspberry pi DHT11 센서 data not good skip error 해결 (0) | 2019.01.27 |
라즈베리파이3 B+ 에 대한 좋은 자료 (0) | 2019.01.18 |
Raspberry Pi GPIO 와 wiringPi 라이브러리 (0) | 2018.11.22 |