0

I'm using a Let's Start Coding Ultimate Kit 1 (it was a christmas present, don't ask) and I'm trying to use this as a typing sort of thing. I haven't implemented the actual letters though.

#include <MakerScreenXVI.h>;

MakerScreenXVI lcd;

int currentNumber = 1;
int ms = 0;
int totalMS = 0;
bool first = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(A0, INPUT);
  pinMode(A3, INPUT);

  lcd.begin();
  lcd.print("Success");
  lcd.setCursor(0,1);
  lcd.print(currentNumber);

}

void loop() {
  delay(200);
  changeNumber();
  delay(200);
}

void clearLCDLine(int line) {               
        lcd.setCursor(0,line);
        for(int n = 0; n < 16; n++) // 20 indicates symbols in line. For 2x16 LCD write - 16
        {
                lcd.print(" ");
        }
}

void changeNumber() {
  if (digitalRead(A0) == LOW) {
    if (first == false) {
      clearLCDLine(1);
      first = true;
    } else {
      first = false;
    }
    currentNumber++;
    if (currentNumber == 27) {currentNumber = 1;}

    lcd.print(currentNumber);
  } else if (digitalRead(A3) == LOW) {
    currentNumber = currentNumber - 1;
    if (currentNumber == 0) {currentNumber = 26;}
    //clearLCDLine(1);
    lcd.print(currentNumber);
  }
} 

For some reason, after it deletes the 1, it stops. Nothing is printed onto the screen, and nothing is cleared from it. How can I fix this? Also, the buttons always return the LOW value. How can I fix this?

1
  • 1
    I don't know the LSCU-Kit, but are there any pull-up resistors at the inputs? If not, can you set the pins with internal pull-ups and try that? Feb 20 '20 at 7:24
0

The buttons will send a LOW signal when pressed if they are set with pinMode INPUT_PULLUP.

The issue with currentNumber not displaying is that after you clear the screen with the 'for' loop, you need to reset the cursor to position 0,1 with lcd.setCursor(0,1); . Otherwise, the numbers are printing out of view.

If I add lcd.setCursor(0,1); just above each line with lcd.print(currentNumber); , I think the code has the behavior you're looking for.

Edit from the person who asked the question:
You also have to add a delay of around 150-200, or else one push will count as many.

2
  • For some reason, I did something (I think with the button and the sockets on the board) and both buttons go down into negatives. I followed your instructions. Before that, you would have to press the down button first (A3) for the other button to work, and then it would show the single digit numbers and a zero. How can I fix this? Feb 21 '20 at 1:02
  • If I understand correctly, you've made some changes to the code, so it's hard to provide direct advice without seeing it. The code you posted above provides "bounds" for the currentNumber variable with the "if" statements. I recommend sending us an email at info@letsstartcoding.com with the code and we may be able to help. Feb 21 '20 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.