Incrementation of number

Hi
I want to make a program with arduino the purpose is increment a number from 10 to 20 (10,11...,19,20) then it return to 10 again so i make a code but it dosen't work can some body help me

so i make a code but it dosen’t work can some body help me

Of course we can help, but we need to see the code

these is the code :

 void frequency(){
for (int i=1; i<=11; i++) 
  { 
      
       freq=freq+(pas*i);
      
     
      if (freq >20)
      { i=1;
      }
       lcd.setCursor(0, 1);
      lcd.print(freq);
       lcd.print(" Mhz ");
      delay (1000);
  break ;

  }
                }

when i want to display the number in LCD it doesn’t stop at 20 but continue

Assuming that the variable 'pas' is a positive number, 'freq' can never go down , because whatever happens, when freq gets to 20, you change the value of the number you are adding to it, but you still carry on adding something to it. However, as you set i to 1, you never leave the loop as it never gets past 11.

That code doesn't compile, so it would be better if you posted all of the sketch.

these all sketch

#include <LiquidCrystal.h>
int freq = 10;
String hertz = " MHZ ";
int pas = 1;

LiquidCrystal lcd(14, 15, 5, 4, 17, 16); //Delcares LCD display pins
unsigned long frq; //Declares an extended size variable for the measured frequency
int cnt;

void setup() {
 
  lcd.begin(16, 2); //LCD display columns and rows
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Frequency :"); //Prints "Frequency /Hz :"
}
  void frequency(){
for (int i=1; i<=11; i++) 
  { 
      
       freq=freq+(pas*i);
      
     
      if (freq >20)
      { i=1;
      }
       lcd.setCursor(0, 1);
      lcd.print(freq);
       lcd.print(" Mhz ");
      delay (1000);
  break ;

  }
                }
    
          

void loop() {

frequency() ;

  
}
int pas = 1;

This is the only place you ever assign pas a value. That means pas will always be 1, so this line here:

freq=freq+(pas*i);

Can be reduced to this:

freq=freq+i;

Furthermore, in a for loop, it's rarely a good idea to set the value of i like you've done here:

if (freq >20)
      { i=1;
      }

What exactly are you expecting from this statement?

  break ;

Well, as pas is fixed and held at 1, and freq starts at 10, first time through the loop, freq is:

freq = 10 + (1 * 1); so it will be 11.
then
freq = 11 + (2 * 1); so now 13
freq = 13 + (3 * 1); so now 16
freq = 16 + (4 * 1); so now 20
freq = 20 + (5 * 1); so now 25

so now, you hit the bit where freq is over 20, so i is set back to 1, so the next time through

freq = 25 + (1 * 1); so now 26 (freq is over 20 still so i set back to 1)
freq = 26 + (1 * 1); so now 27 (freq is over 20 still so i set back to 1)

add infinitum, adding 1 until you get bored and switch it off.

anasch:
…increment a number from 10 to 20 (10,11…,19,20) then it return to 10 again

Try:

//declare int i OUTSIDE of loop() 

  void frequency(){
  for (i=10; i<21; i++)  {   //a for loop can start at any int value you want
      //This will count from 10 to 20.
      freq=i;      // see below
      lcd.setCursor(0, 1);
      lcd.print(freq);  //or lcd.print(i);  which will do the same without the line freq=i; 
      lcd.print(" Mhz ");
      delay (1000);
  }
}       

void loop() {

frequency() ;
  
}