/* This program uses wiringPi to read from a pushbutton switch on a PiFace and then uses that input to control the output of an onboard LED */ #include #include #include #define PIFACE 200 #define LED (PIFACE+2) //This is LED 2 #define BUTTON (PIFACE+0) //This is S1 using namespace std; int main() { //The state of the switch bool val; cout << "Using PiFace" << endl; //For terminal output interface cout << "Switch: "; //These methods must be called before working with // PiFace/wiringPi wiringPiSetupSys(); piFaceSetup(PIFACE); //Infinite loop for(;;) { //Enable S1 pullUpDnControl(BUTTON,PUD_UP); //Read the state of S1 (1 is up, 0 is down) val = digitalRead(BUTTON); //Show this state on LED2 digitalWrite(LED,val); //Show this state in a debugging terminal cout << val; //Do this to keep the output down to one line cout << "\b"; } return 0; }