#include "USI_TWI_Master.h"
#include "MAX44009.h"
-double MAX44009getlux() {
- volatile uint8_t b1,b2;
+uint8_t checkMAX44009(uint8_t nr) {
+ volatile uint8_t b1;
+ nr=(nr<<1)&0x02f;
+ I2c_StartCondition();
+ I2c_WriteByte(0b10010100|nr);
+ I2c_WriteByte(0x03);
+ I2c_StartCondition();
+ I2c_WriteByte (0b10010101|nr);
+ b1 =I2c_ReadByte(NO_ACK);
+ I2c_StopCondition();
+ return b1!=0xFF;
+
+}
+
+
+double MAX44009getlux(uint8_t nr) {
+ volatile uint8_t b1,b2;
+ nr=(nr<<1)&0x02f;
I2c_StartCondition();
- I2c_WriteByte(0b10010100);
+ I2c_WriteByte(0b10010100|nr);
I2c_WriteByte(0x03);
I2c_StartCondition();
- I2c_WriteByte (0b10010101);
+ I2c_WriteByte (0b10010101|nr);
b1 =I2c_ReadByte(NO_ACK);
I2c_StopCondition();
I2c_StartCondition();
- I2c_WriteByte(0b10010100);
+ I2c_WriteByte(0b10010100|nr);
I2c_WriteByte(0x04);
I2c_StartCondition();
- I2c_WriteByte (0b10010101);
+ I2c_WriteByte (0b10010101|nr);
b2 =I2c_ReadByte(NO_ACK);
I2c_StopCondition();
uint8_t exponent = (b1 & 0xF0) >> 4;// upper four bits of high byte register