1.1k
This is a simple example using the Waveshare DVK512. You press a key and this is displayed on the command line, one of the 4 LEDs is also lit for each of the 4 buttons on the board
You can see the LEDS (9) and Buttons (10) in the picture below
Code
[codesyntax lang=”cpp”]
/* key.c * you can build this like: * gcc -Wall key.c -o key -lwiringPi * sudo ./key */ #include <stdio.h> #include <string.h> #include <errno.h> #include<wiringPi.h> char KEY[]={21,22,23,24}; char LED[]={25,26,27,28}; unsigned char i; int main(){ if (wiringPiSetup() < 0)return 1 ; for(i=0;i<4;i++) { pinMode (LED[i],OUTPUT) ; } for(i=0;i<4;i++) { pinMode (KEY[i],INPUT) ;//pinMode (LED, OUTPUT) ; pullUpDnControl(KEY[i], PUD_UP); } while(1) { for(i=0;i<4;i++) { if (digitalRead (KEY[i]) == 0) { printf ("press the key : %d\n",i) ; digitalWrite (LED[i], 1) ; delay(500); digitalWrite (LED[i], 0) ; } } } }
[/codesyntax]
Link
DVK512 # Raspberry Pi Model 2 B/B+/A+ Expansion/Evaluation Development Board with various interfaces