Hello!
At first: i'm sorry for my bad english!
here is my problem:
I'm a newbie with arduino. At the moment I'm trying to implement the game "whac-a-mole" with arduino and processing.
the processing part already works really good with the mouse.
the arduino part:
i use 7 buttons, each button is a molehill. My problem is, that the loop is too fast - if i press the button for too long, than the programm thinks that i pressed it twice - any ideas how i can check if the button was pressed once or multiple times?
this is the source for checking the buttons (just for the first 3 buttons):
// choose the input pin (for a pushbutton)
int inPin_1 = 3;
int inPin_2 = 4;
int inPin_3 = 5;
// variable for reading the pin status
int val_1 = 0;
int val_2 = 0;
int val_3 = 0;
// variable to send state of the buttons to processing
int send = 0;
// button already pressed?
boolean buttonState = true;
// just for testing
int ledPin =13;
void setup() {
// declare pushbutton as input
pinMode(inPin_1, INPUT);
pinMode(inPin_2, INPUT);
pinMode(inPin_3, INPUT);
pinMode(ledPin, OUTPUT); //testing
Serial.begin(9600);
}
void loop(){
send=0;
buttonpress();
}
void buttonpress(){
// stay inside the loop till a button was pressed
while(buttonState){
// read input value
val_1 = digitalRead(inPin_1);
val_2 = digitalRead(inPin_2);
val_3 = digitalRead(inPin_3);
if (val_1 == LOW) {
buttonState=false;
send_byte = send_byte | 1;
digitalWrite(ledPin, HIGH); //testing
Serial.println("1"); //testing
break;
}
if (val_2 == LOW) {
buttonState=false;
send_byte = send_byte | 2;
digitalWrite(ledPin, HIGH); //testing
Serial.println("2"); //testing
break;
}
if (val_3 == LOW) {
buttonState=false;
send_byte = send_byte | 4;
digitalWrite(ledPin, HIGH); //testing
Serial.println("3");
break;
}
else{
digitalWrite(ledPin, LOW);
}
}
printByte(send);
delay(100);
buttonState=true;
}
thanks for answers,
selestra