|
Hi,
Sorry for not beening specific, i am new to this.
the problem is the first part of the code, one for interact with sensor. I dont know how to write it. This is my best try... it is modification of several examples. I was hoping for some advices.
code for mode 1 and 2 work Just fine i Just cant connect it all for sensor to recognize.
hope i explain it better tjan last time
|
|
|
|
|
The only thing I can see change between the two modes is the delay
int led = 13;
int mode = 1; static int delay1[2] = {500, 0}; static int delay2[2] = {500, 5000};
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH); delay(delay1[mode-1]); digitalWrite(led, LOW); delay(delay2[mode-1]);
if (mode == 1) mode = 2; else mode = 1;
}
In vino veritas
|
|
|
|
|
I have an application in which time values are transferred byte-by-byte to an Arduino via USB/COM. I have now realised that using CTime objects will suffer from the 19 January 2038 problem where, after this date, GetTime() will return negative values due to the return value being signed. It appears that use of COleDateTime with CTimeSpan ::GetTotalSeconds will avoid this as the return value is an unsigned quantity.
I have now written a bit of test code comparing CTime and the ColeDateTime. /CtimeSpan combination. Whilst the values returned by the various member functions (year, month, etc,etc) all give identical values, the GetTime() and GetTotalSeconds() values differ by 3600 (1 hour)
Here is my test code:-
CTime tNow;
tNow = CTime::GetCurrentTime();
int iTimeYear = tNow.GetYear();
int iTimeMonth = tNow.GetMonth();
int iTimeDay = tNow.GetDay();
int iTimeHour = tNow.GetHour();
int iTimeMinute = tNow.GetMinute();
int iTimeSecond = tNow.GetSecond();
unsigned long ulNow = tNow.GetTime();
COleDateTime epoch(1970,1,1,0,0,0);
COleDateTime tCurrentTime;
tCurrentTime = COleDateTime::GetCurrentTime();
int iOleYear = tCurrentTime.GetYear();
int iOleMonth = tCurrentTime.GetMonth();
int iOleDay = tCurrentTime.GetDay();
int iOleHour = tCurrentTime.GetHour();
int iOleMinute = tCurrentTime.GetMinute();
int iOleSecond = tCurrentTime.GetSecond();
unsigned long ulOleTime = (unsigned long)(tCurrentTime-epoch).GetTotalSeconds();
Doug
|
|
|
|
|
one hour difference between CTime and COleDateTime is because COleDateTime ignores daylight saving time
i would not care much about 2038, because today's code will be antique at that time
if these time values will be shared across multiple devices then i would use CRT functions
time_t now = time(NULL);
|
|
|
|
|
Hi Serkan,
I thought that originally, but COleDateTime MUST be taking account of DST as the GetHour() function returns the correct value. Thinking about it overnight, I'm beginning to think that I should have applied DST when generating epoch - that would fit the symptoms, wouldn't it ?
(The Arduino works with an unsigned quantity, so it will not be a problem !)
After thought:-
I now believe that the problem is due to taking the DIFFERENCE between Current Time and epoch (I actually got this code off the internet, but didn't do much thinking about it !!!) If DST is applied inherently to all OleDateTime objects, then taking the difference effectively removes any adjustment due to DST, So that would account for it for GetTime() and GetTotalSeconds() being 3600 seconds different !!
Doug
modified 28-Mar-16 5:01am.
|
|
|
|
|
ColeDateTime stores a time stamp value without information about time zone and DST. It is up to you to know if the value is local time or UTC. If you use COleDateTime::GetCurrentTime to initialise it, it will hold a local time value. If you use the constructor or assignment operator accepting a time_t or _time64_t value, it will be UTC when the time_t value has been retrieved using time() and not adjusted afterwards.
If you need to store time stamp values for later use, store them as UTC. This avoids wrong values and simplifies calculation of time spans. If you need to display times as local times, perform the conversion just before display.
See also Time Format Conversion Made Easy[^] here at CP.
|
|
|
|
|
Hello Jochen, I was not aware that the timestamp obtained from COleDateTime would depend on how the object was initialised. Therefore in my test code the object epoch would result in a UTC value, whereas that obtained from the other object (which initialised via GetCurrentTime()) would be localtime. This then blows my "difference" explanation as to why the result from CTime is 3600 seconds different from the COleDateTimeSpan object. My Arduino code expects time quantities to be received as localtime (i.e. adjusted for DST)
Doug
|
|
|
|
|
Still learning how to code wrote: My Arduino code expects time quantities to be received as localtime (i.e. adjusted for DST) You should change that to UTC if possible. When your Arduino uses a different time zone than your Windows system, the results would be wrong again.
|
|
|
|
|
Reviewing some old projects I met a function like this:
bool func()
{
bool var = false;
if(...)
return var = false;
else
return var = true;
}
Actually what the function returns? I think true , because assigning can't be false .
VII. 36. When you surround an army, leave an outlet free. Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: Actually what the function returns? I think true , because assigning can't be false .
There is an easy way to know !
- make a program that will execute that code.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Any assignment is also an expression which has the value of the assigned value.
if(...)
return var = false; else
return var = true;
Some programmers make use of this fact like this:
int x;
while ((x = SomeFunction()) > 0)
{
}
Whether or not this is good style is up to personal preference..
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
RomTibi wrote: I think true , because assigning can't be false . True (regardless).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
RomTibi wrote: because assigning can't be false . Of course it can. This is easy to test by writing a few lines of code.
|
|
|
|
|
Adam works in the in networking security cell. He wants to generate secret keys
following a pattern. The pattern consists of the characters X and Y.
where X means increasing and Y means decreasing. Help him devise an
algorithm to generate the secret key which is the minimum number encoded
following that pattern. Digits from 1-9 and digits can’t repeat.
Sample Input: Sample Output:
X 12
YXYX 21435
YYXYYXXY 321654798
|
|
|
|
|
Sorry, we do not do your homework.
|
|
|
|
|
We don't do your HomeWork.
Advice try to solve the problem by habd, see how you build the solution.
try to device a program that will follow the same processus.
It is not so difficult.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
i know nothing about vector in c. if anyone could provide me link of it n also if someone could give me brief intro i will be obliged
|
|
|
|
|
|
There is no vector in C !
Just arrays.
Advice read C documentation.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
hi all,
i draw a image when i preview it its display ok but when i print with multiple page.
on first page its drawimage correctly but after first page it return generic error.
i really dont understand what happen here.
i m using this to draw image.
Graphics graphics(pDC->GetSafeHdc());
Image myPNG(path);
if(myPNG.GetLastStatus()!=Ok)
{
return FALSE;
}
Gdiplus::Status stat;
stat = graphics.DrawImage(&myPNG, (INT)image_rect.left, (INT)image_rect.top, 300, 300);
return TRUE;
thanks in advance.
|
|
|
|
|
Where in your application is this code being called? Is it inside your OnDraw function, or somewhere else?
|
|
|
|
|
i m used it in
OnPrint(CDC* pDC, CPrintInfo* pInfo) function,
i really dont understand when i preview this image is visible
when i print these page ,on first page its print after first page return Generic Error on drawimage function.
|
|
|
|
|
The only thing you can do is to step through it in the debugger to try and isolate what is happening.
|
|
|
|
|
is there any role of PageUnit or PageScale,
i u using
graphics.SetPageUnit(UnitPixel);
coz when i debug i dint recongze the problem,
in preview the image is display and when i print the error comes.
function is same for both.
modified 26-Mar-16 2:53am.
|
|
|
|