Continue to Site

# Problem in taking users's inputs ~

Status
Not open for further replies.

#### Tarneem

##### Newbie level 6
Hi ;

I m facing problem in taking inputs from the user by using push buttons ~

Here is the code of the function that taking from the user the inputs ..
(inc= increments , Dec= decrements , Next to exit )

Code:
Timerr() // set Timer
{
k=1;
minutes=0;
while(K!=6)
{
if(inc==0)
{minutes++;
Lcd_Cmd(0xc0);
Lcd_Out_Cp(minutes);
}

if(dec==0)
{
minutes=minutes--;
Lcd_Cmd(0xc3);
Lcd_Out_Cp(minutes);
}

if(next==0)
{k=6;while(next==0);}
}
}

this is just to have the input form the user ,, but in each time that i clicked , it shows me garbage values ..

Any one can help ..??
Plz :-(

#### Vbase

##### Full Member level 6
When you click inc or dec the minutes keep on counting and displaying new value while your finger is on the button.
Add this kind of line while(next==0);

#### mdorian

##### Member level 2
You also have to skip push button transitions
Maybe something like this would be better:
Code:
Timerr() // set Timer
{
k=1;
minutes=0;
Lcd_Cmd(0xc0);
Lcd_Out_Cp(minutes);// to see something if no button pressed
while(K!=6)
{
while(inc==0)
{minutes++;
Lcd_Cmd(0xc0);
Lcd_Out_Cp(minutes);
i=0
do {
delay_ms(100);//  small delay to skip transitions
i++;
} while ((i<5) & (inc==0))// repeat with long delay if button still pressed
}
.............

#### betwixt

##### Super Moderator
Staff member
To work as text on an LCD you can't just use 0 to 9, you have to use 0x30 to 0x39 (48 to 57 in decimal) and maybe cater for numbers outside that range too.

Brian.

#### mdorian

##### Member level 2
I missed that ,if you're using MikroC ,a string must be passed to Lcd_Out_Cp.
Use a conversion function like ByteToStr
Code:
char txt[4];
.....
ByteToStr(minutes,txt);
Lcd_Cmd(0xc0);
Lcd_Out_Cp(txt);
assuming that minutes is a char

#### Tarneem

##### Newbie level 6
sir , It's give me better result ..

peevishly it was shown me garbage values .. but now it shows numbers only .. ^_^
Thank u so muuuuch mdorian and every one else helped ..

but still i m having problem .. now see .. this is the initialization

Code:
 char seconds = 0;
char minutes = 0;
char i;
char txt[4];

and this is the function of timer in main :

Code:
if(Timer==0)    //check Timer set button press
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,"Countdown  ");
Timerr();    //call Timer set function
}

and her is the function Timerr():

Code:
Timerr() // set Timer
{
k=1;
minutes=0;
Lcd_Cmd(0xc4);
ByteToStr(minutes,txt);// to see something if no button pressed
while(K!=6)
{
if(inc==0)
{ minutes++;while(inc==0);
ByteToStr(minutes,txt);
Lcd_Cmd(0xc4);
Lcd_Out_Cp(txt);
}

if(dec==0)
{
minutes--; while(inc==0);
ByteToStr(minutes,txt);
Lcd_Cmd(0xc4);
Lcd_Out_Cp(txt);
}

if(next==0)
{k=6;while(next==0);}
}
}
}

The problem is when i first ckliked inc buttons , it shows mw 46 then i cliked again it shows 78 then 22 then 53 ...

What do u think the problem can be ? ?

- - - Updated - - -

IT woooooooorks ..

Thanks for every body who helped me .. I m really thankful to u ppl so much

Yes .. I m using MikroC program ,, and this is the initialization data :

This is the if statment in main function :
Code:
char seconds = 0;
char minutes = 0;
char i;
char txt[4];

Code:
if(Timer==0)    //check alarm set button press
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,"Countdown  ");
Timerr();    //call Timer set function

for (i=60; i >= 0; i--)
{
seconds = i;
minutes = i / 60;
seconds = seconds - (minutes * 60);
Delay_ms(500);
IntToStr(seconds, txt);
Lcd_Out(2, 5, txt);
IntToStr(minutes, txt);
Lcd_Out(2, 1, txt);
Delay_ms(100);
}

and this is the Timerr() function :

Code:
Timerr() // set Timer
{
k=1;
minutes=0;
Lcd_Cmd(0xc4);
ByteToStr(minutes,txt);// to see something if no button pressed
while(K!=6)
{
if(inc==0)
{ minutes++;while(inc==0);
ByteToStr(minutes,txt);
Lcd_Cmd(0xc4);
Lcd_Out_Cp(txt);
}

if(dec==0)
{
minutes--; while(dec==0);
ByteToStr(minutes,txt);
Lcd_Cmd(0xc4);
Lcd_Out_Cp(txt);
}

if(next==0)
{k=6;while(next==0);}
}
}

I want to take the minutes that is taken from the user and start the countingdown function ..

the role that i wrote is nor function right ..

minutes = i / 60;
seconds = seconds - (minutes * 60);

Any one can suggest me a good way to do that ?

Thank u so much again .. i really appreciated

#### betwixt

##### Super Moderator
Staff member
Code:
if(seconds == 60)
{
seconds = 0;
minutes++;
}

Brian.

#### Vbase

##### Full Member level 6
Code:
if(seconds == 60)
{
seconds = 0;
minutes++;
}

Brian.

It's a countdown;
Code:
if(seconds == 255)
{
seconds = 59;
minutes--;
}
Brian, I believe you can improve on this code.

Last edited:

#### Tarneem

##### Newbie level 6
IT dowsn't work by this way =(

- - - Updated - - -

I m working now by this way ..

But I m having problem ..

when I entered 4 munits .. It show in LCD 3 : 59 and stopped .. it is not conteniously decreasing

Code:
if(Timer==0)    //check alarm set button press
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,2,"Countdown  ");
Timerr();    //call Timer set function

while (minutes)
{
minutes--;
ByteToStr(minutes,txt);
Lcd_Cmd(0xc2);
Lcd_Out_Cp(txt);
for ( i=59 ; i>0 ; i-- )
{
seconds = 59;
byteToStr(seconds,txt);
Lcd_Cmd(0xc6);
Lcd_Out_Cp(txt);
Delay_ms(500);
seconds--;

if (seconds==0)
{minutes--;
ByteToStr(minutes,txt);
Lcd_Cmd(0xc2);
Lcd_Out_Cp(txt);}
}
}

- - - Updated - - -

DOOOOOOONE ..

the problem has been fixed .. ALHamduleAllah .. ~

Thank u so much for ur help ..

I really thankfull to u ALL .. ~

ALHamduleAllah!!

#### Tarneem

##### Newbie level 6
Last edited:

Status
Not open for further replies.