Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
en:c_16x2lcd_interrupt [2015/05/08 18:41] john1117 |
en:c_16x2lcd_interrupt [2015/05/08 18:42] (current) john1117 |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Button Interrupt example ====== | ||
+ | gcc -o wiring_isr wiring_isr.c -lwiringPi -lpthread | ||
+ | ./wiring_isr | ||
+ | Push your SW1 on 16x2lcd board | ||
+ | <file c wiring_isr.c> | ||
+ | #include <stdio.h> | ||
+ | #include <wiringPi.h> | ||
+ | |||
+ | int volatile btnCounter; | ||
+ | |||
+ | void myInterrupt(void) | ||
+ | { | ||
+ | btnCounter++; | ||
+ | } | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | if (wiringPiSetup() < 0) { | ||
+ | printf("wiringPiSetup error.\n"); | ||
+ | return 1; | ||
+ | } | ||
+ | if (wiringPiISR(5, INT_EDGE_FALLING, &myInterrupt) < 0) { | ||
+ | printf("wiringPiISR error.\n"); | ||
+ | return 1; | ||
+ | } | ||
+ | |||
+ | while(1) { | ||
+ | printf("%d\n", btnCounter); | ||
+ | delay(1000); | ||
+ | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </file> |