getting strange int values

Hey there,
I have written a small programm, and some things started to behave strange under cirtain conditions. When I display the int I think is reponsible for the problems, it display very strange values, such as

44
„SÓHˆÒ
šSˆ48‡!Sj
›j„MLH¨Â
›¦ˆ54‡¡Ój
›Sˆ57‡¡j
›NC!j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j„j

the 44 seems like a normal value, but the rest looks like a memory addressing problem or something in that order to me.

Any idea what I did wrong, or what could chause an integer to show such values??

Any idea what I did wrong

You didn't post any clues or code.

Could I just point out that this is the third topic you've started in the programming section without actually posting any code?

 if(keyStat == 1){//LONG PRESS AKTION BEGINN
      keyCount = keyCount + 1; //KEY CYCLE CONTINUS COUNTER
    }
    else{
      keyCount = 0;
    }
    if(keyCount > enterSpeed){// basically how long it takes to initiate long button press aktion
       if(change>0){
        if(currentValue+1 <= maxValue){
          currentValue = currentValue + change;  //changing value on long button holds per run
        }
       }
       if(change<0){
        if(currentValue-1 >= minValue){
          currentValue = currentValue + change; 
        }
       }
        keyCount = keyCount - changeSpeed; //reseting the count to a certain level to get the value to change slower "benni"
    }

thats the code I am looking at....

Well that code doesn't print anything or even compile, does it, so let's stop the vague hand-waving, shall we?

oh sorry, forgot to mention: The value gets printed in a different function. It is the keyCount. The baud rate seems to be fine. I am getting correct readings most the time. Can anyone tell what these readings could be??

I'm sorry, I forgot too - I'm currently looking at Bryan Ferry performing "Jealous Guy".

Does that help at all?

Are we just going to sit here viewing the topic, or are you going to join in and post more details?

Well I will post whatever you ask me to. If you want to I can also post the entire sourcecode...
So what would you like me to post. The code does not change the value any more.

Like I said, enough of the hand-waving.

Do you want help or not?

(Does the "Java" in your handle refer to the island, the coffee or the programming language?)

Of course, I wouldn't have askedif I dont't wanted. And I am thankfull you are trying to help me, but I am quite a noob on programming, so you will have to tell me what to do to make helping me easier...

I (or anyone else on the forum) cannot see your code.
The only code you've posted so far doesn't compile and even if it did, could not possibly exhibit the problem you described NINE posts ago.

What do you think you should do?

Do not post snippets of code. The problem is not within the code you posted - when people post snippets, almost always, the problem isn't in the snippet they posted. That's why we hate snippets here.

Post a complete sketch that compiles, which demonstrates the problem.

You haven't even said how the data is being output.... lcd screen? serial monitor? Something else?

Thats the entire sourcecode, the part I have shown you sor far is from the button function, the long press part of it.

Arduino_UI.ino (4.14 KB)

button.ino (1.59 KB)

Storage.ino (1.28 KB)

And for those of us replying from mobile devices just POST THE DAMN CODE.

The output is over serial monitor. If I view it on the lcd, the strage values don't show up.

Well I don't know if thats what you wanted, but thats the main file of the script:

#include <Boards.h>
#include <Firmata.h>

/*Small display manager for 16, 2 LCD display. Able to use and display multiple layers per page. Easy t edit and add pages
 * written by Johannes Zeiser 25.01.2016
 */
#include <EEPROM.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

boolean firstRun = true;
const int key0=40;
const int key1=41;
const int key2=42;
const int key3=43;
const int led0=8;
const int pager=7;
const int lcdled=9;
int temp=0;
int keyCount;
int pdel=0;

boolean writeStorg = false;

int page=0; //current page menu is on
int lastpage=0; //page used in last cycle

const int maxpage=4; //tells the max page count. Used to specify the number of pages. Don't use minpage to increase page count.
const int minpage=0; //should almost always stay at 0

int pagelay=0;//tells which layer of the page is currently used. 0 is the normal cycling menu, 1 is for editing values.
int lstpagelay=0;
const int minPagelay=0;
const int maxPagelay=1;

int count=0;

int keyCountArray[4];
int keyStatArray[4];
boolean buzzerstat = false;
int led0stat = 0;
int lcdledstat = 10;
boolean intRead = false;

char page4[6] = "hello";
int page4num[6];
int iCursor = 0;
boolean curs = false;
void setup() {
lcd.begin(16, 2);
pinMode(key0, INPUT);
pinMode(key1, INPUT);
pinMode(key2, INPUT);
pinMode(key3, INPUT);
pinMode(led0, OUTPUT);
pinMode(pager, OUTPUT);
pinMode(lcdled, OUTPUT);
}

void loop() {
 
  count = keyCountArray[2];
   Serial.begin(9600);
   Serial.println(count);
lcd.setCursor(11, 1);
lcd.print(count);
//storage();
  //Input processing
pagelay = button(key3, maxPagelay+1, minPagelay-1, pagelay, 1, false);
if(pagelay > maxPagelay){
  pagelay = minPagelay;
}
if(pagelay < minPagelay){
  pagelay = minPagelay;
}
 if(pagelay == 0){ //enter page cycler
    //key+
  page = button(key2, maxpage+1, minpage-1, page, 1, true);
    //key-
  page = button(key1, maxpage+1, minpage-1, page, -1, true);
  if(page > maxpage){ //infinite page run
    page = minpage;
  }
  if (page < minpage){
    page  = maxpage;
  }//infinite page run end
}// exit page cycler
if(page != lastpage){
  lcd.clear();
  firstRun = true;
}
//page1 funktion
if(page == 0){
  lcd.setCursor(0, 0);
  lcd.print("LED ON/OFF");
  if(pagelay == 1){
    //KEY-
  led0stat = button(key1, 10, 0, led0stat, -1, true);
    //KEY+
  led0stat = button(key2, 10, 0, led0stat, 1, true);
  }

 //led0stat output streamer
  lcd.setCursor(0, 1);
  lcd.print(led0stat);
  if(led0stat < 10){
    lcd.setCursor(1, 1);
    lcd.print(" ");
  }
}
 //page2 funktion
if(page == 1){
  lcd.setCursor(0, 0);
  lcd.print("page 2");
  lcd.setCursor(0, 1);
  lcd.print("Yeeees!!");
}
//page3 funktion
if(page == 2){
lcd.setCursor(0, 0);
lcd.print("Buzzer ON/OFF");
lcd.setCursor(0, 1);
  if(buzzerstat == true){
    lcd.print("ON ");
  }
  else{
    lcd.print("OFF");
  }
 if(pagelay == 1){
    buzzerstat = button(key2, 1, 0, buzzerstat, 1, true);
    buzzerstat = button(key1, 1, 0, buzzerstat, -1, true);
  }
}
if(page == 3){
  if(page != lastpage){
  lcd.setCursor(0, 0);
  lcd.print("LCD brightness");
  }
  if(pagelay == 1){
   //KEY-
   lcdledstat = button(key2, 10, 0, lcdledstat, 1, true);
   lcdledstat = button(key1, 10, 0, lcdledstat, -1, true);
    
  }
  lcd.setCursor(0, 1);
  lcd.print(lcdledstat);
 if(lcdledstat < 10){
   lcd.setCursor(1, 1);
   lcd.print(" ");
 }
}
if(page == 4){
  if(page != lastpage || firstRun == true){
    lcd.setCursor(0, 0);
    lcd.print("Text input");
    lcd.setCursor(0, 1);
    lcd.print(page4);
  }
  if(pagelay == 1){
    if(curs == false){
      lcd.setCursor(8, 1);
      lcd.cursor();
      curs = true;
    }
  }
  else{
    lcd.noCursor();
    curs = false;
  }
}
//generall output stream
analogWrite(led0, led0stat*25.5);
analogWrite(lcdled, lcdledstat*25.5);
if(buzzerstat == true){
  digitalWrite(pager, HIGH);
}
else{
  digitalWrite(pager, LOW);
}
if(lstpagelay != pagelay || firstRun == true){
  if(pagelay == 0){
    lcd.setCursor(15, 1);
    lcd.print(" ");
    lcd.setCursor(15, 0);
    lcd.print("*");
  }
  if(pagelay == 1){
    lcd.setCursor(15, 0);
    lcd.print(" ");
    lcd.setCursor(15, 1);
    lcd.print("*"); 
  }
}
lastpage=page;
lstpagelay=pagelay;
if(firstRun == true){
  firstRun = false;
}
  
}

and thats the button function, the previous code is from

int button(int key, int maxValue, int minValue, int currentValue, int change, boolean longPress){
  
boolean keyStat = 0; //setting keyStat to 0 to prevent errors
int countNumber = key - 40;//calculating the bank of the array the keyCounter is contained in
boolean keyStat1 = 0;
const int changeSpeed = 50;
const int enterSpeed = 60;

keyCount = keyCountArray[countNumber];
keyStat1 = keyStatArray[countNumber];
keyStat = digitalRead(key);

if(longPress == 1){
 if(keyStat == 1){//LONG PRESS AKTION BEGINN
      keyCount = keyCount + 1; //KEY CYCLE CONTINUS COUNTER
    }
    else{
      keyCount = 0;
    }
    if(keyCount > enterSpeed){// basically how long it takes to initiate long button press aktion
       if(change>0){
        if(currentValue+1 <= maxValue){
          currentValue = currentValue + change;  //changing value on long button holds per run
        }
       }
       if(change<0){
        if(currentValue-1 >= minValue){
          currentValue = currentValue + change; 
        }
       }
        keyCount = keyCount - changeSpeed; //reseting the count to a certain level to get the value to change slower "benni"
    }
}//LONG PRESS AKTION END
    if(keyStat == 1 && keyStat1 == 0){//SINGLE PRESS AKTION
      if(change>0){
        if(currentValue+1 <= maxValue){
          currentValue = currentValue + change; 
        }
       }
       else{
        if(currentValue-1 >= minValue){
          currentValue = currentValue + change; 
        }
       }
     } 
     
 keyCountArray[countNumber] = keyCount; //putting the count out to the array
 keyStatArray[countNumber] = keyStat;
 return currentValue;
}

Take the Serial.begin out of loop() and report back.

If you have to post the code again, use the auto format tool on it first.

now I am the code does not compile any more. I am getting this error: Serial deos not name a type. I moved it to the setup, as well as the part before setup.

Is there anything else to the file? If not, why is the button function in a different set of code tags than the rest of the sketch? It wouldn't compile if the button() function wasn't in the same file, unless it's part of Boards.h?

Also, which point that an integer is displayed does it mess up?

What do you get out if you print that line to the serial monitor? Are the numbers you get out still wrong?

Also, do you have an actual example of what it shows? It can't be what you posted in OP, because it's a 16x2 LCD, but you posted lines longer than 16 characters.

Serial does not name a type? I think you moved it outside of a function. You want it in setup()

POST THE CODE.

Seriously, how hard is it for you to understand that we cannot see what you can see?

Serial deos not name a type.

That is NOT the error you're getting.