Go Down

Topic: Input stops working (Read 1 time) previous topic - next topic

ExuZ

I'm making a Tetris game with an LCD screen and 4 buttons. The game is complete with control and scoring mechanism.
But when I'm trying to add initials to my high score system it stops taking input from all of the buttons.

This code should according to my intention  display the three initials, which it does. after the initials there is a counter, displaying seconds since startup. This too works as intended.

The last ,j, variable should increase once every time i press the right button. See below for the right() code. Sadly it does not, and i have no clue as to why. Any clever minds out there who can help me with this?


The program will never exit the while loop, but that is not a problem for now.
Code: [Select]
String typeInitials(){
  boolean initialsSet = false;
  String initials = "MMM";
  int i = 0;
  int j = 0;
  int currentChar = initials.charAt(0);
 
  while(!initialsSet){
    lcd.setCursor(i+5, 3);
    lcd.print(initials);
    lcd.print(millis()/1000);
    lcd.print(" ");
    if(right()){
      j += 1;
    }
    lcd.print(j);
  }
  return initials;
}


right()
Code: [Select]
boolean right(){
  if (Right == HIGH) {     
    if (Rf == 1){
      Rf = 0;
      return true;
    }
  }else {
    Rf = 1;
  }
  return false;
}

PaulS

Where does the right() function actually determine if a button is pressed?

ExuZ

the Right variable, is the pin connected to the button and it's HIGH while pressed.
Rf is a flag bit, in order to make sure it returns true only once per time the button is pressed.

It also works perfect during the game play.

PaulS

Quote
the Right variable, is the pin connected to the button and it's HIGH while pressed.

Wrong. The Right variable is valued every time analogRead is called to value it. I don't see, though, where analogRead is called.

Post ALL of your code if you really want help.

ExuZ

Well there's my problem. the rest of the program is running in the void loop(), and from there i update the buttons every iteration.
In my high score while loop, I was not.

I'll probably post the code later tonight if it work as intended.

thanks a lot!

Go Up