On line 160 of the above code I attempt to convert the char array s[] to an int. Try as I might however i cannot seem to get it to work. The serial print on 163/164 pops out 0. If i change it to print s[0] or s[1] it prints the digits perfectly, so s[] is definitely getting filled correctly.
I know it's something stupid I'm doing but after a couple of days of research I cannot see the issue with my logic/syntax
Arh.... this is the issue with learning multiple languages at once. I thought the fact I had not specified a length when declaring the arrays meant a \0 was automatically added.
By not specifying a length, it allocated the memory based from what you initialise it to. You initialised it to 2 bytes, which allows 1 character and a null terminator. You needed space for 2 characters and a null terminator.
You make a string but not with ASCII numbers. I see: s[0] = key; and s[0] = key; But an ASCII '0' is 0x30. So why do it the hard way of making is "ASCII" but simply create the right time in the switch? I mean, the input is clearly not serial. So the first 2 cases become:
switch (ctr)
{
case 0:
if (key == 14)
key = 0;
time = key; //put it straight in there
ctr ++;
lcd.clear();
lcd.print("Secs:");
p = key;
lcd.print(p);
break;
case 1:
if (key == 14)
key = 0;
time = key * 10; //you want is to be the ten digit so just multiply
ctr ++;
lcd.clear();
lcd.print("Secs:");
lcd.print(p);
p = key;
lcd.print(p);
break;
Because I was being a moron. First time i've picked this up since last week, I can remember trying to figure it out in each case and directly putting it into "time" but couldn't work the math in my head. Obviously too tired.
Just given it another go and got it in one. You are right, should have avoided the whole situation by directly assigning. I am still curious what I was doing wrong regarding atoi mind. At the beginning of the year I was building c-based trie and hash table data structures, stupid that taking a few off to learn html, php and css leaves me unable to operate the simple stuff !
Either way, it is now working, had to change a few things around further down the code but tis all for the better