반응형
라즈베리파이 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 |
반응형
'개발자 > Raspberry Pi' 카테고리의 다른 글
| raspberry pi i2c, spi 동작 안 할 때 확인할 것 (0) | 2015.03.10 |
|---|---|
| 라즈베리 파이2 에 관해 알아야 할 5가지. (0) | 2015.03.10 |
| 라즈베리 파이 2 gpio 업데이트 - raspberry pi 2 gpio not work (0) | 2015.03.10 |
| 라즈베리파이 GPIO 제어 wiringPi 라이브러리의 설치 방법 (3) | 2015.02.11 |
| Tutorial: Comparing the Arduino and Raspberry Pi (0) | 2015.01.27 |
| pi4j 사용시 GPIO 21 사용법 (0) | 2015.01.17 |
| 라즈베리 파이 케이스들 이미지 모아 봄~ (0) | 2015.01.13 |
| 라즈베리파이 자동 로그인(Auto Login on the RaspberryPi) 설정 (0) | 2015.01.08 |
취업, 창업의 막막함, 외주 관리, 제품 부재!
당신의 고민은 무엇입니까? 현실과 동떨어진 교육, 실패만 반복하는 외주 계약,
아이디어는 있지만 구현할 기술이 없는 막막함.
우리는 알고 있습니다. 문제의 원인은 '명확한 학습, 실전 경험과 신뢰할 수 있는 기술력의 부재'에서 시작됩니다.
이제 고민을 멈추고, 캐어랩을 만나세요!
코딩(펌웨어), 전자부품과 디지털 회로설계, PCB 설계 제작, 고객(시장/수출) 발굴과 마케팅 전략으로 당신을 지원합니다.
제품 설계의 고수는 성공이 만든 게 아니라 실패가 만듭니다. 아이디어를 양산 가능한 제품으로!
귀사의 제품을 만드세요. 교육과 개발 실적으로 신뢰할 수 있는 파트너를 확보하세요.
지난 30년 여정, 캐어랩이 얻은 모든 것을 함께 나누고 싶습니다.
귀사가 성공하기까지의 긴 고난의 시간을 캐어랩과 함께 하세요.
캐어랩