create a loop in Nokia 3310 programme

Hi everyone
I bought myselve the Nokia 3310 shield for Arduino and tried out some examples. Everything worked fine but now I want to modify the code below a little bit.

#include "nokia_3310_lcd.h"
#include "avr_bmp.h"


//keypad debounce parameter
#define DEBOUNCE_MAX 15
#define DEBOUNCE_ON  10
#define DEBOUNCE_OFF 3 

#define NUM_KEYS 5

#define NUM_MENU_ITEM	4

// joystick number
#define UP_KEY 3
#define LEFT_KEY 0
#define CENTER_KEY 1
#define DOWN_KEY 2
#define RIGHT_KEY 4

// menu starting points

#define MENU_X	10		// 0-83
#define MENU_Y	1		// 0-5



// adc preset value, represent top value,incl. noise & margin,that the adc reads, when a key is pressed
// set noise & margin = 30 (0.15V@5V)
int  adc_key_val[5] ={30, 150, 360, 535, 760 };
int sec;
int minute;

// debounce counters
byte button_count[NUM_KEYS];
// button status - pressed/released
byte button_status[NUM_KEYS];
// button on flags for user program 
byte button_flag[NUM_KEYS];

// menu definition
char menu_items[NUM_MENU_ITEM][12]={
	"TEMPERATURE",
	"CHAR MAP",
	"DEMO",
	"ABOUT"	
};

void (*menu_funcs[NUM_MENU_ITEM])(void) = {
	clock,
	charmap,
	bitmap,
	about
};

char current_menu_item;


Nokia_3310_lcd lcd=Nokia_3310_lcd();

void setup()
{
    
   // setup interrupt-driven keypad arrays  
   // reset button arrays
   for(byte i=0; i<NUM_KEYS; i++){
     button_count[i]=0;
     button_status[i]=0;
     button_flag[i]=0;
   }
  
  // Setup timer2 -- Prescaler/256
  TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
  TCCR2B &= ~(1<<WGM22);
  TCCR2B = (1<<CS22)|(1<<CS21);      
  
  ASSR |=(0<<AS2);

   // Use normal mode  
   TCCR2A =0;    
     //Timer2 Overflow Interrupt Enable  
     TIMSK2 |= (0<<OCIE2A);
     TCNT2=0x6;  // counting starts from 6;  
   TIMSK2 = (1<<TOIE2);    
   
                  
 
  SREG|=1<<SREG_I;
  
  lcd.LCD_3310_init();
  lcd.LCD_3310_clear();
  
   //menu initialization
   init_MENU();
   current_menu_item = 0;	
}


/* loop */

void loop()
{
    byte i;
    for(i=0; i<NUM_KEYS; i++){
       if(button_flag[i] !=0){
            
            button_flag[i]=0;  // reset button flag
			switch(i){

				case UP_KEY:
					// current item to normal display
					lcd.LCD_3310_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_NORMAL );
					current_menu_item -=1;
					if(current_menu_item <0)  current_menu_item = NUM_MENU_ITEM -1;
					// next item to highlight display
					lcd.LCD_3310_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_HIGHLIGHT );
					break;
				case DOWN_KEY:
				// current item to normal display
					lcd.LCD_3310_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_NORMAL );
					current_menu_item +=1;
					if(current_menu_item >(NUM_MENU_ITEM-1))  current_menu_item = 0;
					// next item to highlight display
					lcd.LCD_3310_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_HIGHLIGHT );
					break;
				case LEFT_KEY:
          init_MENU();
					current_menu_item = 0;
					break;   
				case RIGHT_KEY:
        	lcd.LCD_3310_clear();
				 	(*menu_funcs[current_menu_item])();
          lcd.LCD_3310_clear();
				 	init_MENU();
					current_menu_item = 0;           
					break;	
                                     
			}
				
		}
    }

}

/* menu functions */

void init_MENU(void){

  byte i;
  
  lcd.LCD_3310_clear();

    lcd.LCD_3310_write_string(MENU_X, MENU_Y, menu_items[0], MENU_HIGHLIGHT );
	
  for (i=1; i<NUM_MENU_ITEM; i++){
    lcd.LCD_3310_write_string(MENU_X, MENU_Y+i, menu_items[i], MENU_NORMAL);
  }
	
	
}

// waiting for center key press
void waitfor_OKkey(){
  byte i;
  byte key = 0xFF;
	while (key!= CENTER_KEY){
    for(i=0; i<NUM_KEYS; i++){
       if(button_flag[i] !=0){
           button_flag[i]=0;  // reset button flag
           if(i== CENTER_KEY) key=CENTER_KEY;
        }
     }
   }
		
}

void clock()
{
        lcd.LCD_3310_write_char_big(50, 1, sec, MENU_NORMAL);
        delay(1000);
        sec+1;
        lcd.LCD_3310_write_char_big(50, 1, sec, MENU_NORMAL);
        if(sec==60);
        {
          minute+1;
        }
        lcd.LCD_3310_write_char_big(50, 1, sec, MENU_NORMAL);
	waitfor_OKkey();
}

void charmap(){
  char i,j;
   for(i=0; i<5; i++){
    for(j=0; j<14; j++){
      lcd.LCD_3310_set_XY(j*6,i);
      lcd.LCD_3310_write_char(i*14+j+32, MENU_NORMAL);
      }
    }
  
  
  lcd.LCD_3310_write_string(38, 5, "OK", MENU_HIGHLIGHT );
	waitfor_OKkey();   
}

void bitmap(){
  lcd.LCD_3310_draw_bmp_pixel(0,0, AND_bmp, 84,48);
  delay(1000);
  lcd.LCD_3310_clear();
  delay(100);
  lcd.LCD_3310_draw_bmp_pixel(15,1, AVR_bmp, 48,24);
  delay(1000);
  lcd.LCD_3310_clear();
  delay(100);
  lcd.LCD_3310_draw_bmp_pixel(0,1, PAC_bmp, 32,32);
  delay(1000);
  lcd.LCD_3310_write_string(30, 2, ".", MENU_NORMAL);
  lcd.LCD_3310_write_string(50, 2, "...", MENU_NORMAL);
  lcd.LCD_3310_write_string(38, 5, "OK", MENU_HIGHLIGHT );
	waitfor_OKkey();
}


void about(){
  
  lcd.LCD_3310_write_string(10, 2, "ARDUINO 101", MENU_NORMAL);
  lcd.LCD_3310_write_string(38, 5, "OK", MENU_HIGHLIGHT );
  waitfor_OKkey();
	
		
}



// The followinging are interrupt-driven keypad reading functions
//  which includes DEBOUNCE ON/OFF mechanism, and continuous pressing detection


// Convert ADC value to key number
char get_key(unsigned int input)
{
	char k;
    
	for (k = 0; k < NUM_KEYS; k++)
	{
		if (input < adc_key_val[k])
		{
           
    return k;
        }
	}
    
    if (k >= NUM_KEYS)
        k = -1;     // No valid key pressed
    
    return k;
}

void update_adc_key(){
  int adc_key_in;
  char key_in;
  byte i;
  
  adc_key_in = analogRead(0);
  key_in = get_key(adc_key_in);
  for(i=0; i<NUM_KEYS; i++)
  {
    if(key_in==i)  //one key is pressed 
    { 
      if(button_count[i]<DEBOUNCE_MAX)
      {
        button_count[i]++;
        if(button_count[i]>DEBOUNCE_ON)
        {
          if(button_status[i] == 0)
          {
            button_flag[i] = 1;
            button_status[i] = 1; //button debounced to 'pressed' status
          }
		  
        }
      }
	
    }
    else // no button pressed
    {
      if (button_count[i] >0)
      {  
		button_flag[i] = 0;	
		button_count[i]--;
        if(button_count[i]<DEBOUNCE_OFF){
          button_status[i]=0;   //button debounced to 'released' status
        }
      }
    }
    
  }
}

// Timer2 interrupt routine -
// 1/(160000000/256/(256-6)) = 4ms interval

ISR(TIMER2_OVF_vect) {  
  TCNT2  = 6;
  update_adc_key();
}

I want to create a loop inside the function "void clock" to start a timer but I have no Idea how to do this. I tried it without theloop like the code below but it will just show a 0 and not the time.

void clock:

void clock()
{
        lcd.LCD_3310_write_char_big(50, 1, sec, MENU_NORMAL);
        delay(1000);
        sec+1;
        lcd.LCD_3310_write_char_big(50, 1, sec, MENU_NORMAL);
        if(sec==60);
        {
          minute+1;
        }
        lcd.LCD_3310_write_char_big(50, 1, sec, MENU_NORMAL);
	waitfor_OKkey();
}

Hope you can help me? :~

sec+1;

Does nothing useful.

sec+=1;

increments "sec"

thx for the advice but what about the loop?

I'm sorry, it isn't clear to me what you're trying to do - I was simply pointing out one of your two programming mistakes in the code you posted.

I'd also look at getting rid of that "delay" call.

Ok. So if I upload the code and and go on programme "clock" the setup will work once. So if i tell the Arduino to start the timer at 0 it will stay there. But when I create a loop in the setup it start counting up from 0 to 1 to 2 to 3... And I am not sure how to tell the Arduino to go on and on with counting up.

        if(sec==60);

If sec contains the value 60, do nothing (;). Otherwise, do nothing.

Why?

        {
          minute+1;
        }

Are those curly braces actually needed?

Dont worry about the code in "clock" I will fix it but how can icreate a loop.

but how can icreate a loop.

Lots of ways. The for statement, the while statement, the do/while statement, even the dreaded goto statement could each be used to create code that executes over and over again.