// // A more sensitive LED light detector. // The LED connected to P2.0 and P2.1 is the sensor. // It should not light up (if it does, you have it in backwards). // The LED connected to P2.2 and P2.3 should light up -- it is // the LED that illuminates anything in front of us. // enum { CHARGE_THE_LED=0b01, READ_THE_LED=~0b01, NO_PULLUP=~0b01, LED_HAS_CHARGE=0b01, LED_PINS=0b11 }; void setup( void ) { delay( 5000 ); Serial.begin( 9600 ); Serial.println( "Light sensor demo" ); P2DIR = 0b1100; P2OUT = 0b1000; } void loop( void ) { P2DIR |= LED_PINS; P2OUT |= CHARGE_THE_LED; P2DIR &= READ_THE_LED; P2OUT &= NO_PULLUP; unsigned long count = 0; while( P2IN & LED_HAS_CHARGE ) count++; for( unsigned x = 0; x < count/10000; x++ ) Serial.print( "#" ); Serial.println( "" ); }