On Oct 1, 2006, at 10:46 AM, Andre Abelian wrote: > if ((adc_x>948)&&(adc_x<954)) // looking for 951 > This is the sort of thing that it's nice to hide inside a macro: #define HOWNEAR 3 #define NEAR(val, target) \ ((val) > ((target) - HOWNEAR) && (val) < ((target) + HOWNEAR)) Then you can say: if (NEAR(adc_x, 951)) { // code } And it's easier to tell what you're trying to do, and you can easily change your "pickyness" by changing HOWNEAR. In your original code example: >> >> if (adc_x==1023) // 5v 1023 >> { >> xbyte_lsb=0xff ; >> xbyte_msb=0x01 ; >> } >> if (adc_x==921) // 4,5v 921 >> { >> xbyte_lsb=0x9A ; >> xbyte_msb=0x01 ; >> } Part of your misunderstanding is because it's indented "wrong"; you didn't un-indent after the first if was done: if (adc_x==1023) // 5v 1023 { xbyte_lsb=0xff ; xbyte_msb=0x01 ; } if (adc_x==921) // 4,5v 921 { xbyte_lsb=0x9A ; xbyte_msb=0x01 ; } BillW -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist