Arduino Slowing Down !!

I have a simple Arduino project with an LCD , IR Sensor , Relay Module ... I'm using an arduino UNO for the project

The LED on the LCD is connected to a Digital pin that supports PWM , at some point the LED on the LCD
get's turned on , after few seconds the LED should start Dimming Slowly(Fading) ...

Well , when I run the project for the first few minutes the Arduino runs fast as it does the Loop void about 26000 times a Second ...

after few minutes the arduino starts slowing down , the slowing down part gets pretty noticeable where the arduino should dim the LED ... where it takes about 10 times the amount of time where the LCD should dim ...

Here is the Code in case needed

http://pastie.org/10986075

most of the code is some calculation for the clock and some Counters....

it's a pretty simple code not sure why the Arduino suddenly slows down ! and most of the time the arduino runs the same code ... (few of IF conditions and the IR result ...)

he Arduino runs fast as it does the Loop void about 26000 times a Second

It does not. It calls the loop() FUNCTION over and over, as fast as it can.

Here is the Code in case needed

No. There is the code. Post it HERE if you want help here. Use Reply, not the Quick Reply field, and the Additional Options link, if your code is too long to post directly.

PaulS:
It does not. It calls the loop() FUNCTION over and over, as fast as it can.
No. There is the code. Post it HERE if you want help here. Use Reply, not the Quick Reply field, and the Additional Options link, if your code is too long to post directly.

Well about the loop running 26000 time a sec it's an approximate for my code ....
you could just ignore the number ...

and I couldn't post the code here , It exceeds the maximum characters ....

and I couldn't post the code here , It exceeds the maximum characters ....

Did you READ what I wrote?

PaulS:
Did you READ what I wrote?

I'm kind of confused ...

I'm kind of confused ...

There is a prompt underneath the last post which says "Reply". Click on that and a new window appears for your reply. At the bottom of that window there is a prompt for "Attachments and other options". Click that, choose your sketch file, attach it.

This is the Sketch

sketch_sep10a.ino (8.96 KB)

I believe that your program is experiencing "death by String" i.e. memory fragmentation.

There have been many discussions over the years in this forum about the use of String objects and their potential problems.
Here's pretty in depth discussion The Evils of Arduino Strings | Majenko's Hardware Hacking Blog

I would suggest that you refactor your program to eliminate the use of the String class and replace them with c-style null terminated character arrays.

Why do you convert to String; you can just as well pass the value directly to your function.

void ProcessRemoteControl(unsigned long Alpha)
{
  switch(Alpha)
  {
    // power button
    case 0x1FE8A75:
      // do something with it
      ...
      ...
      break;
    // OK buttoms
    case 0x1FEB04F:

      // do something with it
      ...
      ...
      break;
    // more cases here
    ...
    ...
  }
}

And call it in loop withProcessRemoteControl(results.value);No need for String (capital S) or c-style string.

As usual I am going to swim against the tide and say that I prefer the code in pastie,org as it means I don't have to download it to my hard disk.

The earlier suggestion that the String class may be causing a problem is certainly valid - although I would expect it to cause a complete crash.

What does the setTime() function do? That is where I would look first for a problem.

...R

Well , as i have understood and i confirmed that the problem is caused by using the Strings …

In this scenario the problem is that each 15secs the PrintClock() method is called , the method uses String …

So I wanted to ask , what do you guys suggest instead of using Strings … since it is hard to do user interfaces without Strings …

I uploaded the updated version of the code , in case needed

Smarthome_Without_Comments.ino (8.13 KB)

strings.
Use strings.

AWOL:
strings.
Use strings.

Well , the problem is caused by using Strings ... ?

So don't use Strings, use strings Instead

Have a look at this link. It describes the String data type and the much preferred alternate, the char array.

https://www.arduino.cc/en/Reference/String

In C, and C++, a string is a NULL terminated array of chars. A String is a memory fragmenting, time wasting, instance of the WString class.

Use strings.

Well , I am trying use the char array ... but Something is wrong

I initialized the char array and I attempted to print the array after initializing (Using Serial print) it prints blanks ??

this is the where I initialize it :

char Clock[7] = {'0','0','0','0','0','0','\0'};

I'm using the following code to print it :

Serial.println((Clock[0] + Clock[1] + ":" + Clock[2] + Clock[3]));

to be specific it doesn't print blanks it prints only the ":" (Colon)

Take some time out to figure out the difference between Strings and strings, and how to use the latter properly.

Serial.println((Clock[0] + Clock[1] + ":" + Clock[2] + Clock[3]));

to be specific it doesn't print blanks it prints only the ":" (Colon)

You can NOT ADD characters in a meaningful way.

This Started to be confusing , so I didn’t use Strings or Chars and the problem still occurs !!

Is it because i’m printing on the LCD too much ??? (Single print each 15 secs)

Or is it because I’m using TimeLib ?

this is the link for the TimeLib Library :

TimeLib