I tried to get the buttons working, but had no luck.
Compiling works with no errors, but I get no answers from the buttons.
button.cpp
#include <iostream> // Include all needed libraries here
#include <wiringPi.h>
#include <stdio.h>
using namespace std; // No need to keep using “std”
int main(void)
{
printf("Initialising WiringPi...\n");
wiringPiSetup(); // Setup the library
const int A_PIN = 5;
const int B_PIN = 6;
const int X_PIN = 16;
const int Y_PIN = 24;
const int R_LED = 17;
const int G_LED = 27;
const int B_LED = 22;
printf("Setting Pin Mode to Inputs...\n");
// Read input on this pin
pinMode(A_PIN, INPUT);
pullUpDnControl (A_PIN, PUD_UP) ;
printf("A_PIN ok\n");
pinMode(B_PIN, INPUT);
pullUpDnControl (B_PIN, PUD_UP) ;
printf("B_PIN ok\n");
pinMode(X_PIN, INPUT);
pullUpDnControl (X_PIN, PUD_UP) ;
printf("X_PIN ok\n");
pinMode(Y_PIN, INPUT);
pullUpDnControl (Y_PIN, PUD_UP) ;
printf("Y_PIN ok\n");
printf("Setting Pin Mode to Outputs...\n");
pinMode(R_LED, OUTPUT);
pinMode(G_LED, OUTPUT);
pinMode(B_LED, OUTPUT);
digitalWrite(R_LED, 0);
digitalWrite(G_LED, 0);
digitalWrite(B_LED, 0);
printf("Listening...\n");
// Main program loop
while(1)
{
//printf("%c",digitalRead(A_PIN));
//printf("\n");
// Button is pressed if digitalRead returns 0
if(digitalRead(A_PIN) == 1) {printf("A ");}
if(digitalRead(B_PIN) == 1) {printf("B ");}
if(digitalRead(X_PIN) == 1) {printf("X ");}
if(digitalRead(Y_PIN) == 1) {printf("Y ");}
delay(500);
}
return 0;
}
I start the program with sudo ./button
.
Can anyone give me a hint what I’m doing wrong?
I’m using cpp because I want to use the buttons of the display hat with the examples of the thermal camera.