Variable Declaration in Arduino

Hello all

I burned Arduino codes in the controller which runs continuously over time.

The project variable declared as int i= 0; is it advisable. Each time in the void loop() function the controller check the condition of the variable "i" to perform some task.

Observation: The LED matrix starts flickering when the program fails to remember the value of variable "i"

Possible Solution: Declaration int i=0 which stores in Registers, whereas long term program usage can I declare the variable as volatile so that it stores in RAM

which is advisable

Thanks in advance

There is no difference, registers are just a special area of RAM.

If you have a bug in your code or hardware you'll need to tell us more about you code and hardware.
IE post the code and a diagram of how things are wired up.

The LED matrix starts flickering when the program fails to remember the value of variable "i"

I can't see a program.

Code has been attached

Master_Slave.ino (13.1 KB)

  if (RTC.read(tm)) 
  setTime(tm.Hour,tm.Minute,tm.Second,tm.Day,tm.Month,tm.Year); // set time to Saturday 8:29:00am Jan 1 2011

If the clock is keeping time, read the time, and adjust the clock so that it is set to the time just read. Add a comment that is completely bogus crap. Why?

  Alarm.delay(2); // wait one second between clock display

Do you need to take your shoes off to count above 1? That code does NOT wait one second.

  EXECUTE=1;

By convention, all capital letter names are reserved for constants. Constants do not appear on the left of the = sign except when initially declared and initialized.

  if (Time_now>=820 && Time_now<1814){
     
     Morning_Reminder_1();

Why are you explicitly calling your alarm callback functions?

     if(SET==1){
       
     m.init();
     m.setIntensity(1);
     SET = false;

SET is a boolean. Why are you comparing it to 1?

  Name.toCharArray(name,Str_Index_two-Str_Index_one);

The second argument to toCharArray() is the size of the buffer.

The code is completely uncommented, except for the useless and incorrect comments that try to state the obvious.

What does the code actually do? What does it do that you don't want? What does it not do that you do want?

Hi Pauls

 if (RTC.read(tm)) 
  setTime(tm.Hour,tm.Minute,tm.Second,tm.Day,tm.Month,tm.Year); // set time to Saturday 8:29:00am Jan 1 2011

I removed the comment it was earlier declared

Alarm.delay(2); // wait one second between clock display

If we dont give this code the internal clock declared using Time.h library is not running

EXECUTE=1;

Removed this line as you suggested

 if (Time_now>=820 && Time_now<1814){
     
     Morning_Reminder_1();

This takes care of calling a specific function when I switch on the module. Otherwise the Alarm function time has to run and call the function.

SET is a boolean. Why are you comparing it to 1?
Is it "1" means boolean "TRUE"

Alarm.delay(2); // wait one second between clock display

If we dont give this code the internal clock declared using Time.h library is not running

Whilst it is true that the TimeAlarms functions depend on using the Alarm.delay() function the code does not do what the comment say it does.

SET is a boolean. Why are you comparing it to 1?
Is it "1" means boolean "TRUE"

That is true at the moment and is unlikely to change, but it would be more sensible to use

if(SET){

or

if(SET== true){

myuino:

EXECUTE=1;

Removed this line as you suggested

Whoops! That's probably removed some vital part of the program. The original comment was more about the coding style. ALLCAPS is usually used to denote a constant.

The solution is to rename EXECUTE everywhere in the program to something else. Choose something more descriptive like ExecuteTheDaleks. There's no limit on how may letters you can use in a variable name although more than 30 gets difficult to read and to type.