I am using the gertboard and wiringPi ,and trying to figure out the buttons. The program reads the low when the pull is pushed, but when not pushed, the input is acting as if it is floating and reading random HIGH and LOW. Im a teacher, new to RaspberryPi, beginner programmer, and am trying to further my knowledge of C. Any help is appreciated. My code is:
#include <wiringPi.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
int main(void)
{
wiringPiSetupGpio();
pinMode(25,INPUT);
pullUpDnControl(25,PUD_UP);
pinMode(17,OUTPUT);
pinMode(24,OUTPUT); //if these unused i/o left not set up. they follow GPIO 17 for some reason
digitalWrite(24,LOW);
pinMode(23,OUTPUT);
digitalWrite(23,LOW);
pinMode(22,OUTPUT);
digitalWrite(22,LOW);
pinMode(21,OUTPUT);
digitalWrite(21,LOW);
pinMode(18,OUTPUT);
digitalWrite(18,LOW);
pinMode(15,OUTPUT);
digitalWrite(15,LOW);
int x=0;
while(x<20)
{
if (digitalRead(25)==LOW)
{
printf("pushed LED ON, %i\n",x);
digitalWrite(17,HIGH);
while (digitalRead(25)==LOW)
{;}
}
if (digitalRead(25)==HIGH)
{
printf("not pushed LED OFF , %i\n",x);
digitalWrite(17,LOW);
while (digitalRead(25)==HIGH)
{;}
x++;
}
}
return 0;
}