I am trying to set a DS1307 Real Time Clock over Serial (xbee serial, the arduino is not connected to a computer).
You use bytes to set the RTC (at least the code that I stole uses bytes):
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
second = 0;
minute = 43;
hour = 0;
dayOfWeek = 5; //sunday = 1
dayOfMonth = 21;
month = 3;
year = 13;
setDateDs1307(); //comment to stop setting the clock on power cycle
I want to be able to run a routine over serial to set the clock using user input.
I have a general function that captures input during the serialEvent() loop, but it is capturing it as a string:
void get_input()
{
char inChar = Serial.read();
if(inChar == 8 || inChar == 127) { //backspace or delete
int len = inputStr.length();
inputStr = inputStr.substring(0, len -1);
} else {
inputStr += (char)inChar;
}
if(inChar == '\n') {
inputStr.trim(); //clean up the string
stringComplete = true;
}
}
I want to be able to enter the format of the time and date over serial (through a menu system) to set the date with the format HH:MM:SS-DD/MM/YY.
Using String.substring(), I will grab the parts of the string I need to set up the variables.
However, my C knowledge is horribly poor...
What I tried to do was this:
second = (byte)inputStr.substring(6, 8);
minute = (byte)inputStr.substring(3, 5);
...
Of course, I get the error "error: invalid cast from type 'String' to type 'byte'"
How can I convert 2 digits of a String into a byte?
And yes, I am aware that using the String class comes with a whole host of other problems, but for most of the menu stuff I am running over serial, it is doing what I need it to do. I'd just like to be able to substring out some parts of the string, stick them into a byte variable, and set my RTC.
Thanks in advance for any suggestions!