|
|
View previous topic :: View next topic |
Author |
Message |
peachgirl Guest
|
a function for get a value with decimal using a keyboard4*4 |
Posted: Mon May 28, 2007 7:46 am |
|
|
Code: | void gestionclavier_virgule()
{
int8 Bouton=0,i=0x00,j=0x00;
float k=1, data=0;
entier=0;
decimal=0;
while(Bouton != '*')
{
Bouton = GetBouton();
if(Bouton == '*')
break;
i = ch_int(Bouton);
printf(lcd_putc, "%d",i);
entier = entier*10 + i;
}
lcd_putc('.');
while(Bouton != '!')
{
Bouton = GetBouton();
if(Bouton == '!')
break;
j = ch_int(Bouton);
printf(lcd_putc, "%d",j);
k=k*0.1;
data=data+k*j;
decimal= float_int8(data);
}
lcd_putc('\f');
}void gestionclavier_virgule()
{
int8 Bouton=0,i=0x00,j=0x00;
float k=1, data=0;
entier=0;
decimal=0;
while(Bouton != '*')
{
Bouton = GetBouton();
if(Bouton == '*')
break;
i = ch_int(Bouton);
printf(lcd_putc, "%d",i);
entier = entier*10 + i;
}
lcd_putc('.');
while(Bouton != '!')
{
Bouton = GetBouton();
if(Bouton == '!')
break;
j = ch_int(Bouton);
printf(lcd_putc, "%d",j);
k=k*0.1;
data=data+k*j;
decimal= float_int8(data);
}
lcd_putc('\f');
} |
In this fuction, "entier" and "decimal" are global variable. this fonction change the value for them.
Now, I have a problem: if I want to enter for example 5, I have to enter 5.0 because of my this function.
I hope you can give me some help for that, or maybe you have a good solution for a decimal value. |
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Tue May 29, 2007 4:58 am |
|
|
Hello,
Your code look to be duplicated.
If i understand, you use '*' for decimal separator and '!' as 'return' key ?
The first loop is breaking only if you type '*'. I think that you need to test for 'return' in this loop too.
as :
Code: |
void gestionclavier_virgule()
{
int8 Bouton=0,i=0x00,j=0x00;
float k=1, data=0;
entier=0;
decimal=0;
while(Bouton != '*' && Bouton != '!')
{
Bouton = GetBouton();
if(Bouton == '*' || Bouton == '!')
break;
i = ch_int(Bouton);
printf(lcd_putc, "%d",i);
entier = entier*10 + i;
}
while(Bouton != '!')
{
lcd_putc('.')
Bouton = GetBouton();
if(Bouton == '!')
break;
j = ch_int(Bouton);
printf(lcd_putc, "%d",j);
k=k*0.1;
data=data+k*j;
decimal= float_int8(data);
}
lcd_putc('\f');
} |
Best regards,
dro _________________ in médio virtus |
|
|
peachgirl Guest
|
|
Posted: Tue May 29, 2007 9:34 am |
|
|
Thank you very much!!!!!!
you are intelligente!!!!
the programm is very good, just change a little, I have changed
I have another question: do you know if "entier" is "signed int8", what can I do for enter a negatif value(-26.5, for example)
inservi wrote: | Hello,
Your code look to be duplicated.
If i understand, you use '*' for decimal separator and '!' as 'return' key ?
The first loop is breaking only if you type '*'. I think that you need to test for 'return' in this loop too.
as :
Code: |
void gestionclavier_virgule()
{
int8 Bouton=0,i=0x00,j=0x00;
float k=1, data=0;
entier=0;
decimal=0;
while(Bouton != '*' && Bouton != '!')
{
Bouton = GetBouton();
if(Bouton == '*' || Bouton == '!')
break;
i = ch_int(Bouton);
printf(lcd_putc, "%d",i);
entier = entier*10 + i;
}
if(Bouton == '*')
lcd_putc('.');
while(Bouton != '!')
{
Bouton = GetBouton();
if(Bouton == '!')
break;
j = ch_int(Bouton);
printf(lcd_putc, "%d",j);
k=k*0.1;
data=data+k*j;
decimal= float_int8(data);
}
lcd_putc('\f');
} |
Best regards,
dro |
|
|
|
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Wed May 30, 2007 1:02 am |
|
|
Hello,
peachgirl wrote: |
you are intelligente!!!!
|
in my case, the experiment makes more than the intelligence. (even if I am a man)
For enter a negative value, i think that you need to use a special key (other than '*' or '!' like '-' if you have in your keyboard) or, you can presses twice '*' for indicate to change the sign. Do not forget that a signed int8 can handle only +127 to -127.
sorry for my bad English (normally, I speak French)
dro _________________ in médio virtus |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|