Cannot get a timer I have been working on to display on an LCD.

Hello, I tried to make a countdown timer with the SimpleTimer library, but I think repeatMe is not getting called which would change the time and update it on the LCD. Ignore the period stuff. It works and lives in another corner of the screen. It is just a period counter because this will later be used to show scores, countdown, and what period the game is in. Any ideas? When I plug it in the time variables don't change.

code:

#include <SimpleTimer.h>
#include <LiquidCrystal_I2C.h>

const int ButtonPin = 2;
const int ButtonPin2 = 4;
int buttonInfo;
int buttonInfo2;
int Period;
int OldP;
int seconds = 10;
int minutes = 10;
int timeOverflowFix = 59;
SimpleTimer timer;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
  pinMode(ButtonPin, INPUT);
  pinMode(ButtonPin2, INPUT);
  lcd.begin();
  timer.setInterval(1000, repeatMe);
  timer.disable(repeatMe);
}

void repeatMe() {
  lcd.begin();
  seconds--;
  if (seconds == 0) {
    seconds += 59;
    minutes--;
  }
}
void loop() {
  buttonInfo = digitalRead(ButtonPin);
  buttonInfo2 = digitalRead(ButtonPin2);
  if (buttonInfo != OldP) {
    if (buttonInfo == HIGH) {
      Period++;
    } else {
    }
    delay(50);
  }
  OldP = buttonInfo;
  lcd.setCursor(12, 1);
  lcd.print("P: ");
  lcd.setCursor(14, 1);
  lcd.print(Period);
  lcd.setCursor(11, 0);
  lcd.print(minutes);
  lcd.print(":");
  lcd.print(seconds);
  if (buttonInfo2 == HIGH) {
    timer.toggle(repeatMe);
    delay(50);
  }
}

Have you tried an example sketch to make sure everything is connected correctly?

.

I think that with this

SimpleTimer timer;

You need to have this in loop

timer.run();

I don't think this syntax is correct.

timer.disable(repeatMe);
timer.toggle(repeatMe);

The argument needs to be a timer ID. Yours maybe 0 or 1.

I tried this, but it didn't work. I did a lot of different combos like one and 0 and tried repeatme, but it's not being called.

ieee488:
Have you tried an example sketch to make sure everything is connected correctly?

.

what do you mean by example sketch?

what do you mean by example sketch?

https://playground.arduino.cc/Code/SimpleTimer/

#include <SimpleTimer.h>

// the timer object
SimpleTimer timer;

// a function to be executed periodically
void repeatMe() {
    Serial.print("Uptime (s): ");
    Serial.println(millis() / 1000);
}

void setup() {
    Serial.begin(9600);
    timer.setInterval(1000, repeatMe);
}

void loop() {
    timer.run();
}

cattledog:
Arduino Playground - SimpleTimer Library

#include <SimpleTimer.h>

// the timer object
SimpleTimer timer;

// a function to be executed periodically
void repeatMe() {
    Serial.print("Uptime (s): ");
    Serial.println(millis() / 1000);
}

void setup() {
    Serial.begin(9600);
    timer.setInterval(1000, repeatMe);
}

void loop() {
    timer.run();
}

I just tried this sketch and it worked repeat me was called.

I just tried this sketch and it worked repeat me was called.

Great. Now read the playground article and use any additional functions as they are described there. The Arduino Playground supplies the documentation you need to understand the use of the library.

In my opinion, your effort will be better spent learning how to use millis() timers, a skill which you will be able to build on in the future, rather than learning how to use a library to manage what is a basic programming task.

Using millis() for timing. A beginners Guide

Demonstration code for several things at the same time

cattledog:
Great. Now read the playground article and use any additional functions as they are described there. The Arduino Playground supplies the documentation you need to understand the use of the library.

In my opinion, your effort will be better spent learning how to use millis() timers, a skill which you will be able to build on in the future, rather than learning how to use a library to manage what is a basic programming task.

Using millis() for timing. A beginners Guide

Demonstration code for several things at the same time

if I use mills() it does it from when the Arduino starts, right? I need to be able to reset it and stuff and not have ti from when it's plugged in.

dwertleplayz:
if I use mills() it does it from when the Arduino starts, right? I need to be able to reset it and stuff and not have ti from when it's plugged in.

Maybe this will help.

if I use mills() it does it from when the Arduino starts, right? I need to be able to reset it

You misunderstand. By using a startTime and subtraction of that startTime from the current millis() value you do not need any reset.

Read this tutorial on millis()
https://www.gammon.com.au/millis