Pages: [1]   Go Down
Author Topic: Array  (Read 409 times)
0 Members and 1 Guest are viewing this topic.
Switzerland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 269
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello
 
I got now GPS working (GPSmap 76 from Garmin) on the Arduino.
So the GPS does give me the Time in UTC. I need now to add or
subtract the a number to fit to my Time Zone.
I do print all information with an array to the serial port.
How do I combine a array of to numbers to an int or something
similar so that I can add a number to correct the time zone?
 
Thx
Andy
Logged

Florida, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 146
meow!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you post your existing source code here, it may help people answer your question.

- Don
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 269
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm ok so I tried this:
Code:

    stunde[j] = linea[j+1];                  //Read the first Number of the the Time (21:15 => stunde[j]=2)
        if (st == 0){                              //So for the first number
            stu = stunde[j];
            if (stu == 49){                        //49=1 so if yes then multipli by ten or just put the stu=10
                stu = 10;
                 }
             if (stu == 50){                       //50=2 so if yes then multipli by ten or just put the stu=20
                 stu = 20;
                 }  
             if (stu == 48){
                 stu = 0;  
                 }
           }
           else{                                         //So for the second number
              stun = stunde[j];
              stu = stu + (stun - 48) + zone;                  //here is the time zone, mine is +2 so the calculation is  for 21:15: 19 + (49-48) + 2
              if (stu >= 24){                                // if its more the 24 like 25 or 26 put it to 00 or 01
                 stu = stu - 24;
                 }
               Serial.print(stu);
               lcd.printIn("Zeit: ");                                     //Zeit menas time in german :)
               lcd.printIn(itoa(stu, buf, 10));
                }
Logged

London
Offline Offline
Faraday Member
**
Karma: 9
Posts: 6247
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a code fragment that may get you in the right direction

Code:
char timeStr[6] = {"12:30"};  // timeStr is our time string, for demo purposes we initialise it to some time
int tzOffset = 1;             // lets say the offset is 1

int hour = ((timeStr[0] - '0') * 10) + timeStr[1] - '0';  // calculate the hour as in integer, in this code we assume the first char will be zero if the time is less than 10 oclock

int localHour = (hr + tzOffset) % 24;  // % is the modulus operator, this is the same as the following:
//if(localHr >= 24)   //          
//   localHr = LocalHr - 24;

char c = (localHr / 10) + '0'; // calculate the tens of hours character
timeStr[0] = c; // and put it into our time string
c = localHr[1] + '0'; // calculate the hours char
timeStr[1] = c; // and put that in the string

//timeStr should now be the local time string
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 269
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Here is a code fragment that may get you in the right direction

Code:
char timeStr[6] = {"12:30"};  // timeStr is our time string, for demo purposes we initialise it to some time
int tzOffset = 1;             // lets say the offset is 1

int hour = ((timeStr[0] - '0') * 10) + timeStr[1] - '0';  // calculate the hour as in integer, in this code we assume the first char will be zero if the time is less than 10 oclock

int localHour = (hr + tzOffset) % 24;  // % is the modulus operator, this is the same as the following:
//if(localHr >= 24)   //          
//   localHr = LocalHr - 24;

char c = (localHr / 10) + '0'; // calculate the tens of hours character
timeStr[0] = c; // and put it into our time string
c = localHr[1] + '0'; // calculate the hours char
timeStr[1] = c; // and put that in the string

//timeStr should now be the local time string



ah great with 3 lines of code it does work much smoother smiley
Code:
int hr = ((timeStr[0]) - '0') * 10 + timeStr[1] - '0';
int st = ((timeStr[3] -'0') *10 + timeStr[4] - '0');
int localHr = (hr + tzOffset) % 24;

thx a lot!!!!!!!


Geko
« Last Edit: August 12, 2008, 12:27:29 pm by GekoCH » Logged

Pages: [1]   Go Up
Jump to: