Go Down

Topic: no matching function for call to string::substring() (Read 51 times) previous topic - next topic

shindingen

#include <LiquidCrystal_I2C.h>
#include <DS3231.h>
int i;
int next_bell = 0;
unsigned long print_counter;
unsigned long current_millis;
unsigned long bell_counter;
String _time;
String _day;
char* bell_times[] = {"07:30", "08:20", "09:00", "09:40", "10:20", "10:50", "11:30", "12:10", "12:50", "13:30"};
LiquidCrystal_I2C lcd(0x27,20,4);
DS3231 rtc(SDA, SCL);//SDA - Pin A4 SCL - Pin A5

void setup() {
  rtc.begin();
  lcd.init();
  lcd.backlight();
  Serial.begin(2000000);
  pinMode(LED_BUILTIN, OUTPUT);
  lcd.setCursor(0,1);
  lcd.print("Next bell: ");

}

void loop() {
  current_millis = millis();

  /* Prints time on the LCD */
  if (current_millis - print_counter > 1000) {
    lcd.home();
    _time = rtc.getTimeStr();
    _day = rtc.getDOWStr();
    lcd.print(_time);
    lcd.setCursor(11, 1);
    lcd.print(bell_times[next_bell]);
    print_counter = current_millis;
  }

  /* Checks bell time */
  if (_time.substring(6) == "00") {
    if (_day.substring() != "Sunday" && _day.substring() != "Saturday") {
      for (i = 0; i < sizeof(bell_times) / 2; i++) {
        if (_time.substring(0, 5) == bell_times) {
          digitalWrite(LED_BUILTIN, HIGH);
          bell_counter = current_millis;
          next_bell += 1;
          if (next_bell > sizeof(bell_times) / 2 - 1) {
            next_bell = 0;
          }
        }
      }
    }
  }

  /*Reset alarm */
  if ((current_millis - bell_counter) > 3000) {
    digitalWrite(LED_BUILTIN, LOW);
  }
}

pert

You aren't using substring() correctly. You need to provide a from argument at a minimum. In addition to being invalid, it also doesn't make sense to try to call it with no arguments. What do you expect that to do?

Please study the documentation to learn how to use substring():
https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/substring/

vaj4088

Also study the locked posts at the top of this forum (and anything that they link to, etc.) to learn how to properly post.  Using code tags would really help.

Go Up