I'm trying to read the button status of the Pi TFT tactile buttons via C++, but it seems that I've hit a wall. The program seems to work, but no button signal is registered.
Since I've hit new land with GPIO-programming, I've followed this guide to write the following program:
Code: Select all
#include <fstream>
#include <string>
#include <iostream>
#include <sstream>
#include "gpioOutput.h"
using namespace std;
string pinNumbers [4] = {"18", "22", "23", "27"};
gpioButton::gpioButton()
{
}
void gpioButton::initGPIO()
{
string gpioDir;
for(int c = 0; c < 4; c++)
{
gpioDir = "/sys/class/gpio/export";
ofstream gpioExport(gpioDir.c_str());
gpioExport << pinNumbers[c];
gpioExport.close();
gpioDir = "/sys/class/gpio/gpio" + pinNumbers[c] + "/direction";
ofstream gpioDirection(gpioDir.c_str());
gpioDirection << "in";
gpioDirection.close();
}
}
void gpioButton::unexportGPIO()
{
string gpioDir;
for(int c = 0; c < 4; c++)
{
gpioDir = "/sys/class/gpio/unexport";
ofstream gpioExport(gpioDir.c_str());
gpioExport << pinNumbers[c];
gpioExport.close();
}
}
bool gpioButton::getValue(int buttonNumber)
{
string gpioDir = "/sys/class/gpio/gpio" + pinNumbers[buttonNumber] + "/value";
ifstream gpioRead(gpioDir.c_str());
string val;
gpioRead >> val;
gpioRead.close();
if(val != "0")
{
cout << "yay";
return true;
}
else
{
cout << "nay";
return false;
}
}
Since there seems to be no change on the GPIO-pins, I've tried measuring the voltage. Oddly enough, it merely toggles between 0V and 45mV, which seems pretty low. Would disabling the pull-up-resistors help? And if it would, how can I disable them via C++?