Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Compilar como gcc -std=c11 -lwiringPi gpio2.c gpio2
- //Test Raspberry B+
- #include <stdio.h> // Used for printf() statements
- #include <wiringPi.h> // Include WiringPi library!
- #define max(array) (sizeof (array)/sizeof(array[0]))//Size
- #define MAX_TEMPO 500
- //GPIO in raspberry B+
- const int IN[]={17,27,22,10,9,11,5,6,13,19,26};//IN
- int IN_ANT[max(IN)];//Guarda el estado actual de la IN
- const int OUT[]={23,24,25,8,7,12,16,20,21};//OUT
- //const int pwmValue = 75; // Use this to set an LED brightness
- int main(void)
- {
- int tempo;
- int boolean;
- int nLed=0;//Numero de OUT o Led
- int nIn=0;//Numero de IN o boton
- wiringPiSetupGpio(); // Initialize wiringPi -- using Broadcom pin numbers
- //Configure inputs
- for (int i=0;i<max(IN);i++){
- pinMode (IN[i],INPUT);//CONFIGURE INPUTS
- //pinMode (IN[i],PUD_DOWN);//Pull down
- pinMode (IN[i],PUD_OFF);
- }
- //Configure outputs
- for (int i=0;i<max(OUT);i++){
- pinMode (OUT[i],OUTPUT);//Configure outputs
- }
- //Bucle principal no intrusivo no blocante como los de tipo delay(xxx)
- while(1)
- {
- if (IN_ANT[nIn]!=(digitalRead(IN[nIn])& 0x01)){//Si ha cambiado, la entrada la muestra
- printf ("IN[%d]=%d\n",nIn,(digitalRead(IN[nIn]) & 0x01));
- }
- IN_ANT[nIn]=(digitalRead(IN[nIn]) & 0x01);//Memoria IN.Lee y guarda estado actual
- if (tempo>=MAX_TEMPO){
- boolean ? digitalWrite(OUT [nLed],HIGH ):digitalWrite(OUT[nLed],LOW);
- //printf ("Led[%d]=%d\n",nLed,boolean & 0x01);
- boolean =~boolean;
- tempo=0;//Reset cronometro ...
- }else {tempo++;}
- // printf (" Led[%d]=%d ",nLed,boolean & 0x01);
- nIn++;//Proxima entrada
- if (nIn>=max(IN)){nIn=0;}
- nLed++;//Proximo Led o salida
- if (nLed>=max(OUT)){nLed=0;}
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement