Searching \ for '[PIC] Re: newbie question - basic logic and a/d co' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/begin.htm?key=a%2Fd
Search entire site for: 'Re: newbie question - basic logic and a/d co'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Re: newbie question - basic logic and a/d co'
2006\01\18@121039 by Sean C. Malloy

picon face
> The following code works
> if(adc_result<0x0F)  //if a/d count is below F then
> ...
> if(0x0F<=adc_result) //if a/d count is above or equal to F then
> ...
>
> but this code does not
> if(0x00<=adc_result<0x0F)  //if a/d is below F then
> ...
> if(0x0F<=adc_result<=0xFF) //if a/d is below F then
> ...
> I'm sure I am overlooking something simple

Since I read this list as a digest, I wouldn't be suprised if someone else
has already answered, but...

In C, the syntax "if ( adc_result < 0x0F )" is valid, while "if ( 0x0F <=
adc_result <= 0xFF )" is not.

A variable can only be compared to a single value, but you may make compound
statements using logical operators ( && for AND and || for OR )

The valid syntax for what you're trying to write would be:

if ( (adc_result >= 0x0F) && (adc_result <= 0xFF) )

Note that it's "&&" and not "&".  Picking up a copy of "The C Programming
Language" by K&R is a great idea if you're trying to learn C syntax.

Good luck.

--
Sean C. Malloy                        spam_OUTsmalloyTakeThisOuTspamio.com

2006\01\18@234701 by andrew kelley

picon face
> In C, the syntax "if ( adc_result < 0x0F )" is valid, while "if ( 0x0F <=
> adc_result <= 0xFF )" is not.

Ah ha.. Learn somethin new everyday.. So thats why whenever I tried to
write(I've been coding in C/C++ for about 8 years)

if(x=somefunc() != 0)
{
printf("hey");
}

That it didnt work.. Figures its some syntax of C.

--
andrew

2006\01\18@235409 by Shawn Wilton

picon face
It would work if you did this instead:

if((x=somefunc()) != 0)
{
 printf("AVR Rules.");
}



On 1/18/06, andrew kelley <.....leetslackerKILLspamspam@spam@gmail.com> wrote:
{Quote hidden}

> -

More... (looser matching)
- Last day of these posts
- In 2006 , 2007 only
- Today
- New search...