Thursday, November 19, 2015

19 October 2015 - Button switch (momentary) example program and Pi 2B J8 Header

// Program button.c
//
#include <wiringPi.h>
#include <stdio.h>

// One side of the button is placed on GPIO 0
// The other side is on 5V

#define BtnPin 0

int
main(
){
    wiringPiSetup();

    pinMode(BtnPin,INPUT);
   

    for(;;)
    {

            if(0==digitalRead(BtnPin))
                {
                   
                    printf("\nButton is NOT Pressed\n");
                }
            if(1==digitalRead(BtnPin))
            {
                    printf("\nButton is Pressed\n");
            }
    }
       
    return(0);
}
   



No comments:

Post a Comment