Results 1 to 1 of 1
  1. #1
    150+ Forum Groupie

    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Alberta, Canada
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Error changes with time

    Arduino UNO. Predicted memory usage 747 bytes of RAM, 20,748 bytes of PROGMEM

    Lower half of frequency would change when the button was pushed and half of another frequency would change when the button was released. This would begin about five minutes after a start or reset and last around five minutes then disappear. Problem eventually traced to declaration of a local variable.

    Declared the local variable as type integer.
    Three lines later a value was assigned to the variable as a result of an "if" statement.
    Next instruction used the variable in a switch / case statement.
    End of void function().

    The variable was not declared with a value. The instruction three lines later wasn't alway met and the default value of 0 was carried into the switch / case function. Case 0: was not assigned so the result for the first five minutes was a null instruction. After five minutes some condition within the processor changes and the variable now starts off with a value of 1 or 2 which do have matching case: instructions. And so it goes until the default goes back to zero about 10 minutes in. Pushing the button met the condition to assign a value other than zero to the variable as instructed. Releasing the button left the variable with whatever the electronic forces place on those two bytes.

    Reduced the size of the sketch uploaded to the Arduino board by combining some code proved to be a temporary fix. Problem re appeared when the sketch was expanded. Free memory was no concern as there was easily 1000 bytes free RAM at all times. Permanent fix was to declare the variable as "int variable = 0;"
    Last edited by BushPilotWannabe; 09-04-2016 at 07:15 PM. Reason: reword the last paragraph
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013