#include #include int main(){ ADMUX=0x40; DDRD=0xff; DDRB=0xff; while (1){ long k=0; unsigned char lowc, highc; unsigned short c, threshlow=250, threshhigh=500; unsigned char d; ADCSRA=0xc0; for (k=0;k<50;k++); lowc=ADCL; // 8 low bits for (k=0;k<30;k++); highc=ADCH; // 2 high bits; must sample both low and high // higher unused bits are reliably zero always c = 256*highc + lowc; // 0..1023 // c = c>>2; // keep 2 high bits and 6 low bits if (c > threshhigh) d=0xff; if (c < threshlow) d=0x00; PORTD=d; } }