Go Down

Topic: membrane in, 7 segment out ... (Read 1 time) previous topic - next topic

Boffin1

#5
Sep 26, 2010, 09:01 am Last Edit: Sep 26, 2010, 10:45 am by John_Smith Reason: 1
So I think I need to work out how to do a boolean function with a character variable ??

and in another example from the library we have :-
void loop()
{
 char key = kpd.getKey();
 if(key)  // same as if(key != NO_KEY)
 {
   switch (key)
 
which seems to be doing the same thing,, I am being a bit blonde this morning  :-/
With my mobile phone I can call people and talk to them -  how smart can you get ?

Korman

#6
Sep 26, 2010, 09:22 am Last Edit: Sep 26, 2010, 09:23 am by Korman Reason: 1
Quote
So I think I need to work out how to do a boolean function with a character variable ??


No you need to work out that == is a compare and = is an assigment and that if you do

Quote
if (customKey ='F' ) { GT++ ;}


you're setting customKey to 'F'.

Korman

Boffin1

#7
Sep 26, 2010, 10:47 am Last Edit: Sep 26, 2010, 10:58 am by John_Smith Reason: 1
Thanks,

I forgot to add the second = again

I will try that
With my mobile phone I can call people and talk to them -  how smart can you get ?

Korman

#8
Sep 26, 2010, 11:05 am Last Edit: Sep 26, 2010, 11:05 am by Korman Reason: 1
To prevent these kinds of errors, it helps to write:
Code: [Select]
if ('F' == customKey) { ... }

For the compare it makes no difference, but if you miss the second =, the compiler will complain about it.

Korman

Boffin1

Thanks  thats a good idea, makes it a bit more foolproof
With my mobile phone I can call people and talk to them -  how smart can you get ?

Go Up