Need to have 2 decimals in lcd.print

Viewed 175

I have this program that prins to an LCD with watchdog interrupt. But the problem is that i need to have 2 decimals after seconds.

the code is as follows:

#include <Arduino.h>
#include "DFRobot_RGBLCD.h"
#include <stm32l4xx_hal_iwdg.h>
#include <Wire.h>
#define I2C2_SCL    PB10
#define I2C2_SDA    PB11
DFRobot_RGBLCD lcd(16,2);
TwoWire dev_i2c (I2C2_SDA, I2C2_SCL);
IWDG_HandleTypeDef watchdog;
void Start();
void Pause();
int paused = 0;
int milli = 0;
volatile byte state = HIGH;

void setup() {
  
  pinMode(A2, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);
  lcd.init();
  Serial.begin(9600);
  
  dev_i2c.begin();
  attachInterrupt(A2, Start, FALLING);
  attachInterrupt(A3, Pause,RISING);

  watchdog.Instance = IWDG;
  watchdog.Init.Prescaler = IWDG_PRESCALER_256;
  watchdog.Init.Reload = 1220;
  watchdog.Init.Window = 0x0FFF;

  HAL_IWDG_Init(&watchdog);
  delay(1);
}

void loop() {
  if(state){
    delay(250);
    lcd.setCursor(0, 0);
    lcd.print("Sekunder: ");
    lcd.print(millis()/1000-pause);

    delay(100);
  }
  else{
    delay(1000);
    paused++;
    HAL_IWDG_Refresh(&watchdog);
  }
}
void Start(){
  state = HIGH;
  HAL_IWDG_Refresh(&watchdog);
  delay(10);
}
void Pause(){
  state = !state;
  delay(10);
}

I have tried to put the -pause outside the lcd.print, but that didnt work. i've also tried this codeline: ``` lcd.print(millis()/1000.0, 2-paused);

But it seems like it takes -paused from the number 2. Do anyone have suggestion to how i can make it work so i get the 2 decimals?
1 Answers
String seconds = String(millis() / 1000.0, 2);
lcd.print(seconds);
Related