Help creating basic function [SOLVED]

I can't work this out, seems very straight forward to me but just doesn't seem to work.

Basically I'm trying to write a basic function that will allow me write on my LCD at a set point, however it just won't compile, I know my GLCD commands work fine because if I put them straight in the loop() they work flawless, code and errors below and any help will be much appreciated.

CODE:

void newStatusBar(string myStatus) {
  GLCD.GotoXY(1, 1);
  GLCD.print(myStatus);
}

void loop() { 
  newStatusBar("My bar text");
  delay(1000);
}

ERROR:

aau_glcd:18: error: variable or field 'newStatusBar' declared void
aau_glcd:18: error: 'string' was not declared in this scope
aau_glcd:72: error: variable or field 'newStatusBar' declared void
aau_glcd:72: error: 'string' was not declared in this scope
aau_glcd.cpp: In function 'void loop()':
aau_glcd:81: error: 'newStatusBar' was not declared in this scope

Try String instead of string.

Or, for better efficiency, try char *

void newStatusBar(char *myStatus) {
  GLCD.GotoXY(1, 1);
  GLCD.print(myStatus);
}

void loop() { 
  newStatusBar("My bar text");
  delay(1000);
}

Thank you majenko I feel really daft for not capitalizing string correctly :frowning:

Can I ask how is using char * more efficient? how does it differ?

Thanks again for the help.

Dave86:
Thank you majenko I feel really daft for not capitalizing string correctly :frowning:

Can I ask how is using char * more efficient? how does it differ?

Thanks again for the help.

String is a class object that has overhead associated with managing it; that translated to more clock cycles and more memory used.

A String is a C++ class, with properties, methods, etc. It's quite memory and resource intensive.

A char * is just a small block of memory with characters in it (an array) with a null byte at the end of it to mark the finish.

char * is harder for the novice programmer to manipulate that a String, but is to be preferred on a system with limited resources like a microcontroller.

I understand now :slight_smile:

Thank you again.