simple function to icrement a variable not working correctly?


hi first post, got first arduino yesterday , have been playing around it. it's interesting can , have particular project in mind once experience. i'm having trouble simple arithmetic function.

basically have lcd screen hooked , buttons, when hit or down keys either increment or decrease value of variable 1 , print result on lcd works fine. when variable gets greater 5 or less 1 want set number jump 1 or 5 respectively sounds simple right?

this have done achieve when run , above 5 continues 6 sets value 2 , when decrease past 1 continues 0 goes 4. going on here?

code: [select]


 int scrollup(){
   
    delay(10);
    m++;
    lcd.setcursor(0, 0);
    lcd.print("^");
    lcd.setcursor(0, 1);
    lcd.print(m);

     if (m > 5){
      m = 1;
      }
 }   
 

 int scrolldown(){
   
    delay(10);
    m--;
    lcd.setcursor(0, 0);
    lcd.print("v");
    lcd.setcursor(0, 1);
    lcd.print(m);

    if (m < 1){
      m = 5;
      }
}

post complete code.  or go www.snippets-r-us.com. 


Arduino Forum > Using Arduino > Programming Questions > simple function to icrement a variable not working correctly?


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

RFID-RC522 with Arduino Pro Micro project. Error on the code?