button read?

heey.. i've been trying to get a read on 2 buttons usin analog pin 0 and 1 but just seems like i just cant get it to work..

problem is that i need it to count every time i press it once.. but it have to not keep counting if i keep it pressed.. so 1 one press = +1 to the count.

i've tryed different scripts but nothing seems to work.. it wont even read a high or low when the button is pressed or not pressed..

here is the 3 different codes i've tryed but nothing have gone right so far so i need some help

int potPin=2;
int button=12;

void setup() {
  pinMode (button, INPUT);
  digitalRead (button);
  Serial.begin(9600);
}
void loop () {
  if (button==0){
    Serial.print("0");
  }
  if (button==1) {
    Serial.print("1"); 
  }
  if (button==2){ 
    Serial.print("2");
  }
}
int button=A1;



void setup() 
{ 
  Serial.begin(9600);
  pinMode (button, INPUT);
  digitalRead (button);
} 

void loop()  
{
  Serial.print(button);
  if (button==0){
    //do nothing
  }
  if (button==1) {
    //do nothing
  }
  if (button==2){ 
    button=0;
  }
  delay(30);
}
int pressed;
 int button = A1;
 int low;



void setup() 
{ 
   pinMode(button, INPUT);
   digitalRead(button);
   low = 1;
   pressed = 0;
  Serial.begin(9600);

void loop()  
{
Serial.print(button)
  if (low == 1)
   {
   if (button == HIGH)
   {
   pressed += 1;
   low = 0;
   }
   }
   if (low == 0)
   {
   if (button == LOW)
   {
   low = 1;
   }
   }
}

the serial print is only for watching what it reading..

and the buttons it connekted to 3.3v and one is connekted to A0 and one is connekted to A1

"button" has the value 12. It can never be HIGH (1) or LOW(0). Try reading the pin denoted by "button" using digitalRead, and assign the value to a variable, say "buttonState", then test that value. Maybe have a look at some of the example code,accessible from the IDE

So what ur sayin is that i can only use pin 12 to read from a button?.. i donno i've just seen someone ude analog 0 to 5 as buttons.. and ok i dee thats wy i cant get it to work with HIGH or LOW.. so how would i solve this problem if i need it to b made as a HIGH or LOW?

ok ill try reading this buttonState but can u give a simpe code that i could work with? (im new to this kind of programming)

and where do i find there example codes? where is this IDE?

Thanks for ur thoughts ^^

So what ur sayin is that i can only use pin 12 to read from a button?.. i donno i've just seen someone ude analog 0 to 5 as buttons..

If I understand you correctly, no, that's not what I'm saying.

I am saying that you need to read a value from a pin, not use the pin number itself.

If you look at the IDE (the Java app you used to write your sketch), you will see under "File / Examples" lots of examples and simple tutorials to help you understand the Arduino.

If you look at your third example, you do read the pin, but don't do anything with the result:

void setup() 
{ 
   pinMode(button, INPUT);
   digitalRead(button);

digitalRead returns a value, but you don't do anything with it.

if i cant use the pin number how do i then read the value from that pin?

ok and thank u for explaining where to find those toturials ^^

If you look at your third example, you do read the pin, but don't doanything with the result: Code: void setup() { pinMode(button, INPUT); digitalRead(button);

digitalRead returns a value, but you don't do anything with it.

yea but i thought i needed to read it like that.. but thanks for infoming.. i've just been trying ti stitch some scripts together to make it work

can u write a script that can read the button and when ever i press it once it will give a value +1 each time. but it have to only give +1 per press.. like if i keep it pressed it only coundts one and not just keeps counting.

Yes, I can write such a script, but I've done it before, and wouldn't be any fun for me.

You'll need to record not that the button is pressed, but that the state of the button has changed from not pressed to pressed, so you'll need to keep a record of what the button was doing last time you looked at it.

You may need to read about debouncing a switch.

thank u very much:)

and if u've made that kinda script b4 maybe give a copy? or at least a cope of the section with the buttons?

and yea ill try this debouncing thing

and if u’ve made that kinda script b4 maybe give a copy?

It’s on paper tape - have you got a reader?

what kind of reader do u mean :P

A paper tape reader.

idk… i could just type it in manualy?

OK, here goes.

First row: no-hole no-hole hole index-hole no-hole hole no-hole no-hol hole hole Second row no-hole hole hole index-hole no-hole hole no-hole no-hole hole.

Of course, I may have it upside down...

(BTW, it's "IDE", not "idk" you type it into)

em ok sorry? no need to b rude… and idk means: i dont kno…

The forum isn’t an SMS or a tweet - there is a character limit, but it is something like 9K characters.
There really is no need for ridiculous txt abbreviations and elisions.

yea but at least u could have said that in a respectable way? i didnt try to insult u or anything?

Did you mean "respectful"?

Can you point out what you found insulting, so I'll know to avoid that form in the future?