Help me with Strings please

My objective is to create Strings of different 1 word statements.

I have a function that I want to:

dataFile.print(String);

The idea is that I want to call the same function to print a String with a timestamp when it is called.

The timestamp is generated using an RTC and logs the correct time and date just fine but I want a single print statement to print different text depending on which case is called from a previous function.

The previous function selects from a range of cases dependent upon a range of frequency inputs. All the cases display text on an LCD and then log the event on an SD card.

void logtime()
{

File dataFile = SD.open(filename, FILE_WRITE);
if (! dataFile)
{
Serial.println("couldnt create file");
return;
}
Serial.print("Logging to: ");
Serial.println(filename);
dataFile.print(String); \This is where I want the string to be sent
DateTime now = RTC.now();
// log time
if (dataFile) {
dataFile.println(now.day(), DEC);
dataFile.print("/");
dataFile.print(now.month(), DEC);
dataFile.print("/");
dataFile.print(now.year(), DEC);
dataFile.println(" ");
dataFile.print(now.hour(), DEC);
dataFile.print(":");
dataFile.print(now.minute(), DEC);
dataFile.print(":");
dataFile.print(now.second(), DEC);
dataFile.println(" ");
Serial.println("Data Logged");
dataFile.println(" ");
dataFile.close();
}
else
{
Serial.println("error opening datalog.txt");
}
}

Can anyone help me as I have yet to successfully use Strings and Pointers to accomplish this task. I assume this is the best method but if anyone can recommend an alternative I would appreciate the guidance.

String is the name of the type. You should put there the name of the variable holding that String. What that might be only you know because you didn't post enough code for us to tell. Post the whole code and we can help you out.

If this is the same code that you are "not allowed to share" as your other post then it is not appropriate to ask your questions here. This is an open source community. This is a place where people share code. If your code is secret then you should work on it yourself or pay someone to do the job. Or at least pare this down to a complete program you can share that exhibits the problem.

Also, read Nick Gammon's "How to" and "Read this" posts at the top of this Forum on the proper way to post source code. With 11 posts, you should be doing this correctly by now.

Here is the full program.

I have multiple issues if you wish to look at the entire lot.

But lets starts with the String pointer issue if anyone can help.

Sorry I am very new to this concept of forums and posting and open source etc etc etc.

Program.txt (8.41 KB)

If anyone else is following this:

That text document I have loaded is a program stores time stamped info onto an SD card based on case selection when events occur and displays time and date that has been established when the program is deployed using an RTC. There is a menu to scroll through that can be used to select different functions to run.

By all means it is not perfect I have lots of bugs I am trying to resolve and any help would be great but for any other newbies like myself this does some basic functions that I spent a while trying to implement.

For the future please attach your program as a ,ino file - or just include it in your Post if it is short enough.

Can you write a short and simple program to illustrate the problem. There is a lot of stuff in the program you have posted that is irrelevant to the problem.

Also, for testing / learning just write a single item to the file.

It is not a good idea to use the String (capital S) class as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

...R

Since we don't know what the actual error is, I can only guess:
Maybe your bug is somewhere else. That print function should be capable of taking a pointer to a char array already.

All I want to achieve is creating a bunch of different blocks of text and then calling a specific one dependent upon my different cases in my mainProgram().

Is there not a simple way to explain how to accomplish this?

ao90:
Is there not a simple way to explain how to accomplish this?

I would try if I could see your code but I can't download your txt file from my phone. Maybe if you posted it in code tags...

//CONSIDER USING MODE OR MEAN METHOD TO REMOVE NOISE THAT WILL BE MEASURED WHEN PUT IN A CABINET//

//Libraries\

#include<LiquidCrystal.h>
#include <Time.h>
#include <TimeLib.h>
#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include <SD.h>

RTC_DS1307 RTC;
File dataFile;

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

char filename[] = "dataFile.txt";

int Htime; // integer variable for on time of a PWM signal
int Ltime; // integer variable for off time of a PWM signal
int Ttime; // integer variable of the total period of the PWM signal in microseconds
int frequency; //The value returned from the freqz function
int freq; //Assigned the value returned from the freqz function
int currentMenuItem = 0;
int lastState = 0;
int x = analogRead (0);
int i = 0;
int programpin = 2;
const int chipSelect = 4;
String PC = "Photocells";

//Setup code here\

void setup() {
pinMode(programpin, OUTPUT);
Wire.begin();
lcd.begin(16, 2); // initiate LCD
// initialize serial communication at 9600 bits per second
Serial.begin(9600); // baud rate for computer serial communication
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
pinMode(chipSelect, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");

RTC.begin();
if (! RTC.isrunning()) {
lcd.print("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
// uncomment it & upload to set the time, date and start run the RTC!
RTC.adjust(DateTime(DATE, TIME));
}
}

void loop()
{
mainMenu();
}

void mainMenu() {
//State = 0 every loop cycle.
int state = 0;
//Refresh the button pressed.
int x = analogRead (0);
//Set the Row 0, Col 0 position.
lcd.setCursor(0,0);

//Check analog values from LCD Keypad Shield
if (x < 100) {
//Right
} else if (x < 200) {
//Up
state = 1;
} else if (x < 400){
//Down
state = 2;
} else if (x < 600){
//Left
} else if (x < 800){
//Select
state = 3;
}

//If we are out of bounds on th menu then reset it.
if (currentMenuItem < 0 || currentMenuItem > 8) {
currentMenuItem = 0;
}
//If we have changed Index, saves re-draws.
if (state != lastState) {
if (state == 1) {
//If Up
currentMenuItem = currentMenuItem - 1;
displayMenu(currentMenuItem);
} else if (state == 2) {
//If Down
currentMenuItem = currentMenuItem + 1;
displayMenu(currentMenuItem);
} else if (state == 3) {
//If Selected
selectMenu(currentMenuItem);
}
//Save the last State to compare.
lastState = state;
}
//Small delay
delay(5);
}

//Display Menu Option based on Index.
void displayMenu(int x) {
switch (x) {
case 1:
clearPrintTitle();
lcd.print ("");
barrierprogram();
break;
case 2:
clearPrintTitle();
lcd.print ("");
break;
case 3:
clearPrintTitle();
lcd.print ("");
break;
case 4:
clearPrintTitle();
lcd.print ("");
break;
case 5:
clearPrintTitle();
lcd.print ("");
break;
case 6:
clearPrintTitle();
lcd.print ("");
break;
case 7:
clearPrintTitle();
lcd.print ("");
break;
case 8:
clearPrintTitle();
lcd.print ("Main Program");
break;
}
}

//Print a basic header on Row 1.
void clearPrintTitle() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Select Program");
lcd.setCursor(0,1);
}

//Show the selection on Screen.
void selectMenu(int x) {
switch (x) {
case 1:
lcd.clear();
lcd.print ("");
bprogram();
break;
case 2:
lcd.clear();
lcd.print ("");
//Call the function that belongs to Option 2
break;
case 3:
lcd.clear();
lcd.print ("");
//Call the function that belongs to Option 3
break;
case 4:
lcd.clear();
lcd.print ("");
//Call the function that belongs to Option 3
break;
case 5:
lcd.clear();
lcd.print ("");
//Call the function that belongs to Option 4
break;
case 6:
lcd.clear();
lcd.print ("");
//Call the function that belongs to Option 4
break;
case 7:
lcd.clear();
SeeSDMemory();
//Call the function that belongs to Option 4
break;
case 8:
lcd.clear();
i = 1;
while (i=1)
{
mainProgram();
}
mainMenu();
//Call the function that belongs to Option 4
break;
}
}

void SeeSDMemory()
{

}

void mainProgram()
{
delay (200);
if (x < 800)
{
i = 0;
mainMenu();
}
freq = freqz();

if (freq < 350)
{
lcd.clear();
lcd.setCursor(0, 0);
DateTime now = RTC.now();
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
lcd.setCursor(0, 1);
lcd.print(now.hour(), DEC);
lcd.print(':');
byte minute = now.minute();
if (minute < 10)
{
lcd.print("0");
}
lcd.print(now.minute(), DEC);
lcd.print(':');
byte second = now.second();
if (second < 10)
{
lcd.print("0");
}
lcd.print(now.second(), DEC);
return;
}

else
{
int range = map(freq, 0, 32000, 0, 80);

switch (range) {

case 1:

setScreen();
lcd.print("");
logtime();
break;

case 2:

setScreen();
lcd.print("");
break;

case 3:

setScreen();
lcd.print("");
break;

case 4:

setScreen();
lcd.print("");
break;

case 5:

setScreen();
lcd.print("");
break;

case 6:

setScreen();
lcd.print("");
break;

case 7:
setScreen();
lcd.print("");
break;
}
}
delay(1); // delay in between reads for stability
}

int freqz()
{
Htime = pulseIn(3,HIGH); // monitors PWM in digital pin 8 and stores high time of the signal in microseconds
Ltime = pulseIn(3, LOW); // monitors PWM in digital pin 8 and stores low time of the signal in microseconds
Ttime = Htime+Ltime; // total period of the signal
frequency =1000000/Ttime; // converts the value of the period to seconds and then calculates frequency (inverse of time)
return frequency;
}
void setScreen()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("");
lcd.setCursor(0,1);
}

void logtime()
{

File dataFile = SD.open(filename, FILE_WRITE);
if (! dataFile)
{
Serial.println("couldnt create file");
return;
}
Serial.print("Logging to: ");
Serial.println(filename);
dataFile.print(Pointer); \This is where I want differennt strings to go
DateTime now = RTC.now();
// log time
if (dataFile) {
dataFile.println(now.day(), DEC);
dataFile.print("/");
dataFile.print(now.month(), DEC);
dataFile.print("/");
dataFile.print(now.year(), DEC);
dataFile.println(" ");
dataFile.print(now.hour(), DEC);
dataFile.print(":");
dataFile.print(now.minute(), DEC);
dataFile.print(":");
dataFile.print(now.second(), DEC);
dataFile.println(" ");
Serial.println("Data Logged");
dataFile.println(" ");
dataFile.close();
}
else
{
Serial.println("error opening datalog.txt");
}
}
void bprogram()
{
for (int j = 0; j < 10; j++)
{
digitalWrite(pin, HIGH);
delay(100);
digitalWrite(pin, LOW);
delay(100);
}
}

Let me help you; this is how you are supposed to post code

type
** **[code]** **

paste your code after that
type
** **[/code]** **
after that

so it looks like'

//CONSIDER USING MODE OR MEAN METHOD TO REMOVE NOISE THAT WILL BE MEASURED WHEN PUT IN A CABINET//

//Libraries\\

#include<LiquidCrystal.h>
#include <Time.h>
#include <TimeLib.h>
#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include <SD.h>

RTC_DS1307 RTC;
File dataFile;

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

char filename[] = "dataFile.txt";

int Htime;                          // integer variable for on time of a PWM signal
int Ltime;                          // integer variable for off time of a PWM signal
int Ttime;                          // integer variable of the total period of the PWM signal in microseconds
int frequency;                      //The value returned from the freqz function
int freq;                           //Assigned the value returned from the freqz function
int currentMenuItem = 0;
int lastState = 0;
int x = analogRead (0);
int i = 0;
int programpin = 2;
const int chipSelect = 4;
String PC = "Photocells";

//Setup code here\\

void setup()
{
  pinMode(programpin, OUTPUT);
  Wire.begin();
  lcd.begin(16, 2);                   // initiate LCD
  // initialize serial communication at 9600 bits per second
  Serial.begin(9600);                 // baud rate for computer serial communication
  while (!Serial)
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.print("Initializing SD card...");
  pinMode(chipSelect, OUTPUT);
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect))
  {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");

  RTC.begin();
  if (! RTC.isrunning())
  {
    lcd.print("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    // uncomment it & upload to set the time, date and start run the RTC!
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop()
{
  mainMenu();
}

void mainMenu()
{
  //State = 0 every loop cycle.
  int state = 0;
  //Refresh the button pressed.
  int x = analogRead (0);
  //Set the Row 0, Col 0 position.
  lcd.setCursor(0, 0);

  //Check analog values from LCD Keypad Shield
  if (x < 100)
  {
    //Right
  }
  else if (x < 200)
  {
    //Up
    state = 1;
  }
  else if (x < 400)
  {
    //Down
    state = 2;
  }
  else if (x < 600)
  {
    //Left
  }
  else if (x < 800)
  {
    //Select
    state = 3;
  }

  //If we are out of bounds on th menu then reset it.
  if (currentMenuItem < 0 || currentMenuItem > 8)
  {
    currentMenuItem = 0;
  }
  //If we have changed Index, saves re-draws.
  if (state != lastState)
  {
    if (state == 1)
    {
      //If Up
      currentMenuItem = currentMenuItem - 1;
      displayMenu(currentMenuItem);
    }
    else if (state == 2)
    {
      //If Down
      currentMenuItem = currentMenuItem + 1;
      displayMenu(currentMenuItem);
    }
    else if (state == 3)
    {
      //If Selected
      selectMenu(currentMenuItem);
    }
    //Save the last State to compare.
    lastState = state;
  }
  //Small delay
  delay(5);
}

//Display Menu Option based on Index.
void displayMenu(int x)
{
  switch (x)
  {
    case 1:
      clearPrintTitle();
      lcd.print ("");
      barrierprogram();
      break;
    case 2:
      clearPrintTitle();
      lcd.print ("");
      break;
    case 3:
      clearPrintTitle();
      lcd.print ("");
      break;
    case 4:
      clearPrintTitle();
      lcd.print ("");
      break;
    case 5:
      clearPrintTitle();
      lcd.print ("");
      break;
    case 6:
      clearPrintTitle();
      lcd.print ("");
      break;
    case 7:
      clearPrintTitle();
      lcd.print ("");
      break;
    case 8:
      clearPrintTitle();
      lcd.print ("Main Program");
      break;
  }
}

//Print a basic header on Row 1.
void clearPrintTitle()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Select Program");
  lcd.setCursor(0, 1);
}

//Show the selection on Screen.
void selectMenu(int x)
{
  switch (x)
  {
    case 1:
      lcd.clear();
      lcd.print ("");
      bprogram();
      break;
    case 2:
      lcd.clear();
      lcd.print ("");
      //Call the function that belongs to Option 2
      break;
    case 3:
      lcd.clear();
      lcd.print ("");
      //Call the function that belongs to Option 3
      break;
    case 4:
      lcd.clear();
      lcd.print ("");
      //Call the function that belongs to Option 3
      break;
    case 5:
      lcd.clear();
      lcd.print ("");
      //Call the function that belongs to Option 4
      break;
    case 6:
      lcd.clear();
      lcd.print ("");
      //Call the function that belongs to Option 4
      break;
    case 7:
      lcd.clear();
      SeeSDMemory();
      //Call the function that belongs to Option 4
      break;
    case 8:
      lcd.clear();
      i = 1;
      while (i = 1)
      {
        mainProgram();
      }
      mainMenu();
      //Call the function that belongs to Option 4
      break;
  }
}

void SeeSDMemory()
{

}

void mainProgram()
{
  delay (200);
  if (x < 800)
  {
    i = 0;
    mainMenu();
  }
  freq = freqz();

  if (freq < 350)
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    DateTime now = RTC.now();
    lcd.print(now.day(), DEC);
    lcd.print('/');
    lcd.print(now.month(), DEC);
    lcd.print('/');
    lcd.print(now.year(), DEC);
    lcd.setCursor(0, 1);
    lcd.print(now.hour(), DEC);
    lcd.print(':');
    byte minute = now.minute();
    if (minute < 10)
    {
      lcd.print("0");
    }
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    byte second = now.second();
    if (second < 10)
    {
      lcd.print("0");
    }
    lcd.print(now.second(), DEC);
    return;
  }

  else
  {
    int range = map(freq, 0, 32000, 0, 80);

    switch (range)
    {

      case 1:

        setScreen();
        lcd.print("");
        logtime();
        break;

      case 2:

        setScreen();
        lcd.print("");
        break;

      case 3:

        setScreen();
        lcd.print("");
        break;

      case 4:

        setScreen();
        lcd.print("");
        break;

      case 5:

        setScreen();
        lcd.print("");
        break;

      case 6:

        setScreen();
        lcd.print("");
        break;

      case 7:
        setScreen();
        lcd.print("");
        break;
    }
  }
  delay(1);                        // delay in between reads for stability
}

int freqz()
{
  Htime = pulseIn(3, HIGH);           // monitors PWM in digital pin 8 and stores high time of the signal in microseconds
  Ltime = pulseIn(3, LOW);            // monitors PWM in digital pin 8 and stores low time of the signal in microseconds
  Ttime = Htime + Ltime;              // total period of the signal
  frequency = 1000000 / Ttime;         // converts the value of the period to seconds and then calculates frequency (inverse of time)
  return frequency;
}
void setScreen()
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("");
  lcd.setCursor(0, 1);
}

void logtime()
{

  File dataFile = SD.open(filename, FILE_WRITE);
  if (! dataFile)
  {
    Serial.println("couldnt create file");
    return;
  }
  Serial.print("Logging to: ");
  Serial.println(filename);
  dataFile.print(Pointer);  \\This is where I want differennt strings to go
  DateTime now = RTC.now();
  // log time
  if (dataFile)
  {
    dataFile.println(now.day(), DEC);
    dataFile.print("/");
    dataFile.print(now.month(), DEC);
    dataFile.print("/");
    dataFile.print(now.year(), DEC);
    dataFile.println(" ");
    dataFile.print(now.hour(), DEC);
    dataFile.print(":");
    dataFile.print(now.minute(), DEC);
    dataFile.print(":");
    dataFile.print(now.second(), DEC);
    dataFile.println(" ");
    Serial.println("Data Logged");
    dataFile.println(" ");
    dataFile.close();
  }
  else
  {
    Serial.println("error opening datalog.txt");
  }
}
void bprogram()
{
  for (int j = 0; j < 10; j++)
  {
    digitalWrite(pin, HIGH);
    delay(100);
    digitalWrite(pin, LOW);
    delay(100);
  }
}

You've already been asked to use [code]code tags[/code] when posting code, but totally ignored it. Your last reply with that extremely long code was a disgrace.

My standard reply:-

You really should have read How to use this forum before posting. (Especially item #7.)

ie Your code and any error messages should always be placed between [code]code tags[/code]. Posting it inline as you have done makes it much harder to read or copy and paste for diagnosis.

P.S. I see that sterretje just said the same as I was typing, but I'll still post this because you might take more notice if a couple of us say it.

//Libraries\\

#include<LiquidCrystal.h>
#include <Time.h>                   
#include <TimeLib.h>
#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include <SD.h>

RTC_DS1307 RTC;
File dataFile;

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

char filename[] = "dataFile.txt";

int Htime;                          // integer variable for on time of a PWM signal
int Ltime;                          // integer variable for off time of a PWM signal
int Ttime;                          // integer variable of the total period of the PWM signal in microseconds       
int frequency;                      //The value returned from the freqz function
int freq;                           //Assigned the value returned from the freqz function
int currentMenuItem = 0;
int lastState = 0;
int x = analogRead (0);
int i = 0;
int programpin = 2;
const int chipSelect = 4;
String PC = "Photocells";

//Setup code here\\

void setup() {
      pinMode(programpin, OUTPUT);
      Wire.begin();
      lcd.begin(16, 2);                   // initiate LCD                               
                                          // initialize serial communication at 9600 bits per second
      Serial.begin(9600);                 // baud rate for computer serial communication
while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.print("Initializing SD card...");
  pinMode(chipSelect, OUTPUT);
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");

  RTC.begin();
  if (! RTC.isrunning()) {
    lcd.print("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    // uncomment it & upload to set the time, date and start run the RTC!
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
 }

void loop() 
{
  mainMenu();   
}  
 
void mainMenu() {
  //State = 0 every loop cycle.
  int state = 0;
  //Refresh the button pressed.
  int x = analogRead (0);
  //Set the Row 0, Col 0 position.
  lcd.setCursor(0,0);
 
  //Check analog values from LCD Keypad Shield
  if (x < 100) {
    //Right
  } else if (x < 200) {
   //Up
    state = 1;
  } else if (x < 400){
   //Down
    state = 2;
  } else if (x < 600){
    //Left
  } else if (x < 800){
    //Select
    state = 3;
  }
 
  //If we are out of bounds on th menu then reset it.
  if (currentMenuItem < 0 || currentMenuItem > 8) {
   currentMenuItem = 0; 
  }
    //If we have changed Index, saves re-draws.
   if (state != lastState) {
      if (state == 1) {
         //If Up
          currentMenuItem = currentMenuItem - 1; 
          displayMenu(currentMenuItem);
      } else if (state == 2) {
         //If Down
          currentMenuItem = currentMenuItem + 1;  
          displayMenu(currentMenuItem);
      } else if (state == 3) {
         //If Selected
         selectMenu(currentMenuItem); 
      }
      //Save the last State to compare.
      lastState = state;
   } 
   //Small delay
  delay(5);
}
 
//Display Menu Option based on Index.
void displayMenu(int x) {
     switch (x) {
      case 1:
        clearPrintTitle();
        lcd.print ("");
        barrierprogram();
        break;
      case 2:
        clearPrintTitle();
        lcd.print ("");
        break;
       case 3:
        clearPrintTitle();
        lcd.print ("");
        break;
      case 4:
        clearPrintTitle();
        lcd.print ("");
        break;
       case 5:
        clearPrintTitle();
        lcd.print ("");
        break;
       case 6:
        clearPrintTitle();
        lcd.print ("");
        break;
       case 7:
        clearPrintTitle();
        lcd.print ("");
        break;
        case 8:
        clearPrintTitle();
        lcd.print ("Main Program");
        break;                  
    }
}
 
//Print a basic header on Row 1.
void clearPrintTitle() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Select Program");
  lcd.setCursor(0,1); 
}
 
//Show the selection on Screen.
void selectMenu(int x) {
   switch (x) {
      case 1:
        lcd.clear();
        lcd.print ("");
        bprogram();
        break;
      case 2:
        lcd.clear();
        lcd.print ("");
        //Call the function that belongs to Option 2
        break;
       case 3:
        lcd.clear();
        lcd.print ("");
        //Call the function that belongs to Option 3
        break;
       case 4:
        lcd.clear();
        lcd.print ("");
        //Call the function that belongs to Option 3
        break;
      case 5:
        lcd.clear();
        lcd.print ("");
        //Call the function that belongs to Option 4
        break;
      case 6:
        lcd.clear();
        lcd.print ("");
        //Call the function that belongs to Option 4
        break;                
      case 7:
        lcd.clear();
        SeeSDMemory();
        //Call the function that belongs to Option 4
        break;    
       case 8:
        lcd.clear();
        i = 1;
        while (i=1)
        {
        mainProgram();
        }
        mainMenu();
        //Call the function that belongs to Option 4
        break;     
        }
}

void SeeSDMemory()
{
  
}

void mainProgram()
{
  delay (200);
  if (x < 800)
  {
    i = 0;
    mainMenu();
  }
  freq = freqz();

if (freq < 350)
{
    lcd.clear();
    lcd.setCursor(0, 0);
    DateTime now = RTC.now();
    lcd.print(now.day(), DEC);
    lcd.print('/');
    lcd.print(now.month(), DEC);
    lcd.print('/');
    lcd.print(now.year(), DEC);
    lcd.setCursor(0, 1);
    lcd.print(now.hour(), DEC);
    lcd.print(':');
    byte minute = now.minute();
    if (minute < 10)
    {
      lcd.print("0");
    }
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    byte second = now.second();
    if (second < 10)
    {
      lcd.print("0");
    }
    lcd.print(now.second(), DEC);
    return;
}  
 
else
{
int range = map(freq, 0, 32000, 0, 80);

switch (range) {               
 
    case 1:      

  setScreen();
  lcd.print("");
  logtime();
  break;
  
    case 2:    

  setScreen();
  lcd.print("");
   break;
    
    case 3: 

  setScreen();
  lcd.print("");
  break;

      case 4:  

  setScreen();
  lcd.print("");
  break;
     
      case 5: 

  setScreen();
  lcd.print("");
  break;

 case 6:

  setScreen();
  lcd.print("");
  break;
   
    case 7:   
  setScreen();
  lcd.print("");
  break;
      }
    }    
  delay(1);                        // delay in between reads for stability
}

  int freqz()
  {
  Htime = pulseIn(3,HIGH);            // monitors PWM in digital pin 8 and stores high time of the signal in microseconds
  Ltime = pulseIn(3, LOW);            // monitors PWM in digital pin 8 and stores low time of the signal in microseconds
  Ttime = Htime+Ltime;                // total period of the signal
  frequency =1000000/Ttime;            // converts the value of the period to seconds and then calculates frequency (inverse of time)  
  return frequency;
  }
void setScreen()
{
  lcd.clear();  
  lcd.setCursor(0,0);
  lcd.print("");
  lcd.setCursor(0,1);
}

void logtime()
  { 
    
  File dataFile = SD.open(filename, FILE_WRITE);
  if (! dataFile) 
    {
  Serial.println("couldnt create file");
  return;
    }
  Serial.print("Logging to: ");
  Serial.println(filename);
  dataFile.print(Pointer);   \\This is where I want differennt strings to go  
  DateTime now = RTC.now();
  // log time
  if (dataFile) {
  dataFile.println(now.day(), DEC);
  dataFile.print("/");  
  dataFile.print(now.month(), DEC);
  dataFile.print("/");
  dataFile.print(now.year(), DEC);
  dataFile.println(" ");
  dataFile.print(now.hour(), DEC);
  dataFile.print(":");
  dataFile.print(now.minute(), DEC);
  dataFile.print(":");
  dataFile.print(now.second(), DEC);
  dataFile.println(" ");
  Serial.println("Data Logged");
  dataFile.println(" ");
  dataFile.close();
  }
   else 
   {
    Serial.println("error opening datalog.txt");
   }
  } 
void bprogram()
{
for (int j = 0; j < 10; j++)
{
  digitalWrite(pin, HIGH);
  delay(100);
  digitalWrite(pin, LOW);
  delay(100);  
}
}

Finally. Thank you. :slight_smile:

You can change

void logtime()
{
  ...
  ...
  dataFile.print(Pointer);  \\This is where I want differennt strings to go
  ...
  ...
}

to

void logtime(char *txt)
{
  ...
  ...
  dataFile.print(txt);  \\This is where I want differennt strings to go
  ...
  ...
}

Now you can pass c-style strings as shown below

like

      case 1:

        setScreen();
        lcd.print("");
        logtime("Hello world");
        break;

it works thank you!