I got a little
atmega32u4 board. Although I bought it for other project I couldn't keep from trying it as USB light sensor. As Erdem's poor man's version delays, here is result of 10 minutes work:
Except the mini board you need a sensor. I used an old photoresistor connected between ADC0 input and GND.
Firmware:
Dean Camera's LUFA, actually Demos/Device/ClassDriver/GenericHID
with only one function changed
Code: Select all
bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
uint8_t* const ReportID,
const uint8_t ReportType,
void* ReportData,
uint16_t* const ReportSize)
{
unsigned char* p= ReportData;
DDRF= 0;
PORTF= 1; // weak pull up for photoresistor
ADMUX= _BV(REFS0); // measure ADC0 with Vcc as a reference
DIDR0= _BV(ADC0D);
ADCSRA= _BV(ADEN) | _BV(ADSC) | _BV(ADIF) | 7; // prescale by 128
while (! bit_is_set(ADCSRA, ADIF));
p[0]= ADCL, p[1]= ADCH;
ADCSRA= 0; // ADC off
PORTF= 0;
*ReportSize = 2;
return true;
}
I admit that data acquisition is not ideal, it needs some averaging.
I added libusb 0.1 code to read the light level and autobright worked same way as with serial connected sensor.
Of course no problems with startup
Now I need couple of days to clean the code for A-series and I'll commit it to svn.
BTW atmega32u4 has many PWM outputs - seems ideal as ambilight LED driver