i'm using RaspberryPI with Wiring libray in c++, and I want to use the wiringPiISR for fire an event when i click my button on PIN 5.
This is the code
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>
#include <unistd.h>
unsigned long last_interrupt_time = 0;
#define PIN 5
//gcc foo.c -o foo -lwiringPi
void myEdge (void)
{
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > 500)
{
delay(200);
if( digitalRead(PIN)== 1 )
fprintf(stdout,"gpio rising\n");
else
fprintf(stdout,"gpio falling\n");
fflush(stdout);
}
last_interrupt_time = interrupt_time;
}
int main (int argc,char **argv)
{
if (wiringPiSetupGpio() < 0)
{
fprintf (stderr, "Errore: Unable to GPIO: %s\n", strerror (errno)) ;
return 1 ;
}
pinMode(PIN, INPUT) ;
pullUpDnControl(PIN, PUD_DOWN) ;
if (wiringPiISR (PIN, INT_EDGE_BOTH , &myEdge) < 0)
{
fprintf (stderr, "Errore: Unable to setup ISR: %s\n", strerror (errno)) ;
return 1 ;
}
while (1)
delay (1000) ;
return 1;
}
I compile white gcc foo.c -o foo -lwiringPi
This code works but fires when I click EVERY PIN... the pin 5, and also the 4 and the 6 and maybe others... WHY? Anyone can help me to understand?